Home > database >  How do you get a count (the number of) of all responses with certain attributes dplyr
How do you get a count (the number of) of all responses with certain attributes dplyr

Time:09-30

Right now my code looks like this:

Data <- Other_Data %>%
  dplyr::filter(Description == "Information" & Category == 1 & Cost >= 1000)

It creates a new table, which DOES give me the count of observations, which does answer the question that I am answering. But, I was wondering if there is a way to simply print the number.

CodePudding user response:

We may use sum

with(Other_Data, sum(Description == "Information" & 
           Category == 1 & Cost >= 1000, na.rm = TRUE))

CodePudding user response:

You have the required data in Data. To get it's count you can do nrow(Data) which will count the number of rows in the Data and return the count that satisfies the condition in filter.

  • Related