【发布时间】:2015-04-02 02:01:33
【问题描述】:
一年是出生年,另一年是季节年;目标是计算特定季节的年龄(以年为单位)。我想获取此信息并在合并数据集中创建一个新字段 (master$playerAge)。我收到一个不熟悉的错误,不确定是什么原因造成的。我已经确认merged.all$yearID 和merged.all$birthYear 都存在于merged.all 中。任何帮助表示赞赏。
代码sn-p:
## calculate age from birthYear and YearId
master$playerAge <- paste(merged.all$yearId - merged.all$birthYear)
Error:
Error in `[<-.data.table`(x, j = name, value = value) :
RHS of assignment to new column 'playerAge' is zero length
but not empty list(). For new columns the RHS must either be
empty list() to create an empty list column, or, have length > 0;
e.g. NA_integer_, 0L, etc.
输入():
Names = c("playerID", "yearID", "teamID", "lgID", "stint", "G", "AB", "R", "SO", "IBB", "HBP" 、“SH”、“SF”、“GIDP”、“salary”、“birthYear”、“birthMonth”、“birthDay”、“birthCountry”、“birthState”、“birthCity”、“deathYear”、“deathMonth”、“ deathDay”、“deathCountry”、“deathState”、“deathCity”、“nameFirst”、“nameLast”、“nameGiven”、“weight”、“height”、“bats”、“throws”、“debut”、“finalGame” , "retroID", "bbrefID", "name", "dob"), sorted = "playerID", class= c("data.table", "data.frame"), row.names = c(NA, - 6L), .internal.selfref = ) > –
【问题讨论】:
-
我不知道你为什么要使用 paste() 函数。如果 'yearID' 和 'birthYear' 是 POSIXct 类型,那么你可以减去它们,不需要 paste()。
-
@Michael - 感谢您的提示。我已经删除了。
-
您应该将
dput编辑到您的问题中,这很糟糕。
标签: r