I am new to R programming. I have to build titanic data in R. I want to find out how many child and adults are there in the dataset. Can someone give me hint to find the same?
I tried using length(
) function but it did not give the result.
I am new to R programming. I have to build titanic data in R. I want to find out how many child and adults are there in the dataset. Can someone give me hint to find the same?
I tried using length(
) function but it did not give the result.
Here's a solution in tidyverse syntax. It converts the Titanic dataset into a tibble (a type of dataframe), groups the data by the Age
column, then uses n()
to count the number of rows at each level of Age
, giving the number of children and adults.
library(tidyverse)
Titanic %>%
as_tibble() %>%
group_by(Age) %>%
summarise(N = n())
This gives the output:
# A tibble: 2 x 2
Age N
<chr> <int>
1 Adult 16
2 Child 16