R data.tree替换有0行,数据有4562:人口统计数据树视图

时间:2018-12-06 04:58:05

标签: r

我正在尝试创建树结构以了解我的数据的人口统计分布。我正在尝试使用data.tree软件包和以下代码:

library(data.tree)
#mydata$age<-as.character(mydata$age) #Converting factor to string has no effect
mydata$pathstring<-paste("AllData",
                                  mydata$age,
                                  sep = '/')
tree.1<-as.Node(mydata)

我不断收到错误消息:

Error in `[[<-.data.frame`(`*tmp*`, pathName, value = character(0)) : 
  replacement has 0 rows, data has 4562

我知道这是R语言中的一个非常普通的错误,但是我无法弄清楚我要去哪里。

一旦我能够构建此基本树,我将为其添加更多级别(变量)。

我正在关注这两个小插曲:

  1. https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html
  2. https://cran.r-project.org/web/packages/data.tree/vignettes/applications.html

编辑

我的data.table中的pathstring变量如下:

mydata$pathstring
   [1] "SurveyResults/45 - 54"     "SurveyResults/55 - 64"     "SurveyResults/75 - 84"     "SurveyResults/25 - 34"    
   [5] "SurveyResults/55 - 64"     "SurveyResults/45 - 54"     "SurveyResults/45 - 54"     "SurveyResults/45 - 54"    
   [9] "SurveyResults/75 - 84"     "SurveyResults/85 +"        "SurveyResults/35 - 44"     "SurveyResults/55 - 64"    
  [13] "SurveyResults/25 - 34"     "SurveyResults/35 - 44"     "SurveyResults/65 - 74"     "SurveyResults/55 - 64"    
  [17] "SurveyResults/25 - 34"     "SurveyResults/35 - 44"     "SurveyResults/25 - 34"     "SurveyResults/45 - 54"    
  [21] "SurveyResults/75 - 84"     "SurveyResults/25 - 34"     "SurveyResults/45 - 54"     "SurveyResults/18 - 24"    
  [25] "SurveyResults/25 - 34"     "SurveyResults/45 - 54"     "SurveyResults/55 - 64"     "SurveyResults/45 - 54"    
  [29] "SurveyResults/45 - 54"     "SurveyResults/45 - 54"     "SurveyResults/45 - 54"     "SurveyResults/55 - 64"    
  [33] "SurveyResults/25 - 34"     "SurveyResults/55 - 64"     "SurveyResults/35 - 44"     "SurveyResults/Undisclosed"  

0 个答案:

没有答案