我编写了三个函数,其中两个函数(即function1和function2 )在populatedataset的另一个函数中使用。
当我收到以下错误时,我正在运行函数populatedatasetError in if (num == 1) { : argument is of length zero
我相信这是由于function2 的'if (num == 1) {: ' 部分造成的。
function2 <- function(data, table, dict) {
personindex <- substr(deparse(substitute(data)), start = 1, stop = 2)
num <- table[person == as.character(personindex)]$newpersonality
if (num == 1) {
proptable <- data %>% inner_join(dict[score == 1]) %>% count(word)
proportion <- sum(proptable$n)/nrow(data)
return(proportion)
}
else {
proptable <- data %>% inner_join(dict[score == 0]) …Run Code Online (Sandbox Code Playgroud)