为一条推文中的多次提及创建边缘(行),问题

Creating edges (rows) for several mentions in one tweet, problems

在 Dave 对 'Creating edges (rows) for several mentions in one tweet' 运行 的回答中,以下脚本:

plyr::ddply(tweets, c("text"), function(x){
mention <- unlist(stringr::str_extract_all(x$text, "@\w+"))
# some tweets do not contain mentions, making this necessary:
if (length(mention) > 0){
    return(data.frame(mention = mention))
} else {
    return(data.frame(mention = NA))    
}}) 

我对某些推文列表有疑问。我收到错误:

Error in if (empty(.data)) return(.data) : 
  missing value where TRUE/FALSE needed.

感谢您的帮助。

比较这两个结果:

if(NA > NA) 'yes' else 'no'
#Error in if (NA > NA) "yes" else "no" : 
#  missing value where TRUE/FALSE needed

if(NA > NA && !is.na(NA > NA)) 'yes' else 'no'
#[1] "no"

第一个表达式返回的错误消息与您出于类似原因收到的错误消息相同。条件测试需要 TRUEFALSE 才能继续。我的测试 NA > NA 没有真值,因此返回 NA。因此,在第二个测试中,我进行了额外的检查以忽略 NA 条件结果。