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

作者: 王诗翔 | 来源:发表于2019-01-10 23:40 被阅读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是使用的是复制-修改机制

    相关文章

      网友评论

        本文标题:【r<-探索】Advanced R 2.1 小测验

        本文链接:https://www.haomeiwen.com/subject/qcttdqtx.html