在 R 中使用函数
Using functions in R
我正在尝试使用函数对矩阵进行一些算术运算,但卡住了。
这里是函数:
tweet.score = function(tweets)
{
#browser()
tweets[,3]<- ifelse(as.numeric(tweets[,1])- as.numeric(tweets[,2]) >= 10,2,1)
return(tweets)
}
sapply(bush1,tweet.score)
此处 bush1 有 3 列,我使用第 1 列和第 2 列(转换为数字)并保存在第三列中
当我 运行 函数外的这一行时,它完美地工作..但是当我使用 Sapply 时,它失败了.. 说 "incorrect number of dimensions"
sapply
不需要
bush1<-tweet.score(bush1)
应该可以
我正在尝试使用函数对矩阵进行一些算术运算,但卡住了。
这里是函数:
tweet.score = function(tweets)
{
#browser()
tweets[,3]<- ifelse(as.numeric(tweets[,1])- as.numeric(tweets[,2]) >= 10,2,1)
return(tweets)
}
sapply(bush1,tweet.score)
此处 bush1 有 3 列,我使用第 1 列和第 2 列(转换为数字)并保存在第三列中
当我 运行 函数外的这一行时,它完美地工作..但是当我使用 Sapply 时,它失败了.. 说 "incorrect number of dimensions"
sapply
不需要
bush1<-tweet.score(bush1)
应该可以