为什么我可能会得到未定义的列错误?

时间:2014-10-16 13:11:08

标签: r data-visualization

我在以下数据集中使用时间轴库:

'data.frame':   3951 obs. of  4 variables:
 $ Problem  : chr  "A" "B" "C" "D" ...
 $ Device   : chr  "V" "W" "V" "W" ...
 $ StartDate: Date, format: "2008-01-24" "2008-01-11" ...
 $ EndDate  : Date, format: "2007-11-25" "2007-10-16" ...

这与图书馆的ww2:

提供的数据结构完全相同
'data.frame':   8 obs. of  4 variables:
 $ Person   : chr  "Franklin D. Roosevelt" "Harry S. Truman" "Stanley\nBaldwin" "Neville\nChamberlain" ...
 $ Group    : chr  "US President" "US President" "UK Prime Minister" "UK Prime Minister" ...
 $ StartDate: Date, format: "1933-03-04" "1945-04-12" ...
 $ EndDate  : Date, format: "1945-04-12" "1953-01-20" ...

我跑完后

timeline(df,group.col=df$Problem,start.col=df$StartDate,end.col=df$EndDate)

返回

Error in `[.data.frame`(df, , start.col) : undefined columns selected

即使我尝试不同的str,例如df [,1],它也会返回相同的错误。我误解了什么?

1 个答案:

答案 0 :(得分:1)

研究文档,然后使用:

timeline(df, group.col="Problem",
             start.col="StartDate",
             end.col="EndDate")