【r<-探索】Advanced R 2.1 小测验

Q

  1. Given the following data frame, how do I create a new column called “3” that contains the sum of 1 and 2? You may only use $, not [[. What makes 1, 2, and 3 challenging as variable names?
df <- data.frame(runif(3), runif(3))
names(df) <- c(1, 2)
  1. In the following code, how much memory does y occupy?
x <- runif(1e6)
y <- list(x, x, x)
  1. On which line does a get copied in the following example?
a <- c(1, 5, 3, 2)
b <- a
b[[1]] <- 10

A

df$`3` = df$`1` + df$`2`
object.size(x)
object.size(y)
  1. 第3行,因为R是使用的是复制-修改机制

你可能感兴趣的:(【r<-探索】Advanced R 2.1 小测验)