I have a list (mylist) of 110 items.
length(mylist)
#[1] 110
The elements within the lists are descriptions. I'm trying sum the elements of the entire list (basically counting the words in each description).
This provides a total for the first element.
length(mylist[[1]])
#[1] 162
Instead of repeating that 110 times, what is the best way to sum all 110 elements? Would a for
statement work?
Thanks.
More generally, use lapply
to apply a function to each element of a list:
lapply(list, length)
If you want to determine element (word) wise count of each component (description) in your list , use
Reduce("+",mylist)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With