我正在尝试在数据框上运行代码直到特定日期。我有个人游戏统计数据,第二列是按顺序排列的日期。我认为这是如何做到这一点,但我得到一个错误:
Error in `[.data.frame`(dfmess, dfmess$Date <= Standingdate) :
undefined columns selected
这是我的代码:
read.csv("http://www.football-data.co.uk/mmz4281/1516/E0.csv")
dfmess <- read.csv("http://www.football-data.co.uk/mmz4281/1516/E0.csv", stringsAsFactors = FALSE)
Standingdate <- as.Date("09/14/15", format = "%m/%d/%y")
dfmess[dfmess$Date <= Standingdate] -> dfmess
答案 0 :(得分:0)
您可能希望在比较之前先将dfmess$Date
转换为as.Date
。另外,根据@Roland的评论,您需要额外的逗号,
:
dfmess <- read.csv("http://www.football-data.co.uk/mmz4281/1516/E0.csv", stringsAsFactors = FALSE)
dfmess$Date <- as.Date(dfmess$Date, "%m/%d/%y")
Standingdate <- as.Date("09/14/15", format = "%m/%d/%y")
dfmess[dfmess$Date <= Standingdate, ]