Currently getting the error message:
Error in UseMethod("type"): no applicable method for 'type' applied to an object of class "factor"
I'm guessing this is because i am passing the wrong type of object through my function but here is my code:
for(i in 1:length(names(testwords))){ allwords <- lapply(testwords[i], function(z)
count = sapply(df.OE[i], function(x) sum(str_count(x, z))))}
Where testwords
is a list of length 15 and df.OE
is a dataframe with 2567 observations and 15 variables. Any ideas why this is occurring or even better how i can solve it
For background: i intend for the for loop to iterate through each list item of testwords (a list of words /terms) and then return the frequency with which these words/ terms occur.
The code i started with was taken from the 2nd part of Julius's answer found here: R count times word appears in element of list
Happy to clarify
Thanks, John
Edit:
This code works:
w <- c("a","q","e")
allwords <- lapply(w, function(z)
count = sapply(df.OE[1], function(x) sum(str_count(x, z))))
So i am assuming the issue is with how pass testwords
through my code?