美文网首页
2020-12-09 第四章基本数据管理1.0

2020-12-09 第四章基本数据管理1.0

作者: L6511 | 来源:发表于2020-12-10 19:59 被阅读0次

    创建新变量92页
    按照书的内容写,出现这个问题
    创建leadership数据框

    > manager<-c(1,2,3,4,5)
    > date<-c("10/24/08","10/28/08","10/1/08","10/12/08","5/1/09")
    > country<-c("US","US","UK","UK","UK")
    > gender<-c("M","F","F","M","F")
    > age<-c(32,45,25,39,99)
    > q1<-c(5,3,3,3,2)
    > q2<-c(4,5,,5,3,2)
    Error in c(4, 5, , 5, 3, 2) : 3元素是空的
    > q2<-c(4,5,5,3,2)
    > q3<-c(5,2,5,4,1)
    > q4<-c(5,5,5,NA,2)
    > q5<-c(5,5,2,NA,1)
    > leadership <- data.frame(manager,data,country,gender,age,q1,q2,q3,q4,q5,stringsAsFactors = FALSE)
    
    Error in as.data.frame.default(x[[i]], optional = TRUE) : 
      cannot coerce class ‘"function"’ to a data.frame
    

    虽然我没有明白到底错哪儿了,但是我想我至少创建数据集,就很简单的创建一下

    > manager<-c(1,2,3,4,5)
    > data<-c("10/24/08","10/28/08","10/1/08","10/12/08","5/1/09")
    > country<-c("US","US","UK","UK","UK")
    > gender<-c("M","F","F","M","F")
    > age<-c(32,45,25,39,99)
    > q1<-c(5,3,3,3,2)
    > q2<-c(4,5,5,3,2)
    > q3<-c(5,2,5,4,1)
    > q4<-c(5,5,5,NA,2)
    > q5<-c(5,5,2,NA,1)
    > date<-c("10/24/08","10/28/08","10/1/08","10/12/08","5/1/09")
    > leadership<-data.frame(manager,date,country,gender,age,q1,q2,q3,q4,q5)> leadership
      manager     date country gender age q1 q2 q3 q4 q5
    1       1 10/24/08      US      M  32  5  4  5  5  5
    2       2 10/28/08      US      F  45  3  5  2  5  5
    3       3  10/1/08      UK      F  25  3  5  5  5  2
    4       4 10/12/08      UK      M  39  3  3  4 NA NA
    5       5   5/1/09      UK      F  99  2  2  1  2  1

    相关文章

      网友评论

          本文标题:2020-12-09 第四章基本数据管理1.0

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