Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count of entries in data frame in R

Tags:

dataframe

r

count

I'm looking to get a count for the following data frame:

> Santa    Believe Age Gender Presents Behaviour 1    FALSE   9   male       25   naughty 2     TRUE   5   male       20      nice 3     TRUE   4 female       30      nice 4     TRUE   4   male       34   naughty 

of the number of children who believe. What command would I use to get this?

(The actual data frame is much bigger. I've just given you the first four rows...)

Thanks!

like image 206
Michael Avatar asked Nov 28 '09 19:11

Michael


People also ask

How do you find the number of entries in a Dataframe in R?

To get number of rows in R Data Frame, call the nrow() function and pass the data frame as argument to this function. nrow() is a function in R base package.

How do I count the number of entries in a table in R?

The ncol() function in R programming That is, ncol() function returns the total number of columns present in the object.

How do I count the number of items in a group in R?

group_by() function along with n() is used to count the number of occurrences of the group in R. group_by() function takes “State” and “Name” column as argument and groups by these two columns and summarise() uses n() function to find count of a sales.

How do I see how many rows a value is in R?

The nrow R function returns the number of rows that are present in a data frame or matrix. Above, you can find the R code for the usage of nrow in R.


1 Answers

You could use table:

R> x <- read.table(textConnection('    Believe Age Gender Presents Behaviour 1    FALSE   9   male       25   naughty 2     TRUE   5   male       20      nice 3     TRUE   4 female       30      nice 4     TRUE   4   male       34   naughty' ), header=TRUE)  R> table(x$Believe)  FALSE  TRUE      1     3  
like image 144
rcs Avatar answered Sep 22 '22 16:09

rcs