数据-R语言-图表-决策-Linux-PythonCook R数据科学与R语言

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

2019-01-10  本文已影响21人  王诗翔

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

猜你喜欢

热点阅读