I have a long list containing different numbers of elements that can also be repeated in the same field. This is an example of the first five lines:
A <- list(c("JAMES","CHARLES","JAMES","RICHARD"), c("JOHN","ROBERT","CHARLES"), c("CHARLES","WILLIAM","CHARLES","MICHAEL","WILLIAM","DAVID","CHARLES","WILLIAM"), c("CHARLES"), c("CHARLES","CHARLES"))
Now I would like to calculate the number of elements for each line of the list.
My desired result would look something like this:
[1] 4 [2] 3 [3] 7 [4] 1 [5] 2
In addition to the fact that I would like to know the frequency, the term "CHARLES" appears on every line.
Based on my example, I would like to get the same result:
[1] 1 [2] 1 [3] 3 [4] 1 [5] 2
I thought about this:
> table(A) Error in table(A) : all arguments arguments must have same length > sum(A) Error in sum(A) : invalid 'type' (list) of argument
But I do not know what to do with these error messages, and, unfortunately, I do not know the alternatives.
I know the number of lines in a list:
> length(A) [1] 5
But this, unfortunately, does not answer my question. I could not find any other answers.
Therefore, I would like to ask you, please, help me calculate these two measures!
Thank you in advance!