Reputation: 693
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 ?
Upvotes: 9
Views: 36529
Reputation: 1134
@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!
Upvotes: 1
Reputation: 81693
If you want to count the strings that are not identical to the empty string (""
), you can use:
sum(dat$exampleColumn != "")
Upvotes: 16