Reputation: 343
I have a file named "gamedata" with 30 columns (a mix of strings, numbers, and logicals), I need to count the number of rows where a string in column "home" matches "Seahawks" AND a partial string match in column "penalty" matches "*holding*".
All I need is a count of the total number of rows where (gamedata$home == "Seahawks" & gamedata$penalty == "*holding*").
I've tried several wrong solutions, which simply result in integer(0), when I can see that there are several valid instances. Your help is appreciated.
Upvotes: 1
Views: 3970
Reputation: 520888
Try using sum(expression)
:
sum(gamedata$home == "Seahawks" & grepl("holding", gamedata$penalty))
Upvotes: 3