I wrote three functions where two of the functions (namely function1 and function2) is used in the other function of populatedataset.
I was running the function populatedataset when i got an error of Error in if (num == 1) { : argument is of length zero
I believe that it is due to function2 due to the 'if (num == 1) {: ' portion.
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]) %>% count(word)
proportion <- sum(proptable$n/nrow(data))
return(proportion)
}
}
populatedataset <- function(data, table, dict) {
list_a <- c(function1(data, dict), function2(data, table, dict))
return (list_a)
}
I have been reading up on this error on other pages but I can't seem to find a solution related to this problem.
I would greatly appreciate any insight into this error!