I just started with R, and i have to count elements from an column that are not empty. For example :
exampleColumn
1 "heey"
2
3 "World"
4 "how are you "
How can I achieve this ?
If you want to count the strings that are not identical to the empty string (""
), you can use:
sum(dat$exampleColumn != "")
@Sven definitely gave the right answer. If you were like me, wondering why
length(dat$exampleColumn != "")
does not work. It's because "length" counts all the TRUE/FALSE evaluations, but "sum" only sums up the TRUE values. A beginner's ah-ha moment!
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