【r

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是使用的是复制-修改机制

猜你喜欢

转载自blog.csdn.net/weixin_34143774/article/details/87528320
2r