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!
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.
The ncol() function in R programming That is, ncol() function returns the total number of columns present in the object.
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.
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.
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
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