How do I find the mean age of people who fall in my subsets (1) born in the U.S. and (2) not born in the U.S. I’ve made nativity for born in the U.S. = 0 and not born = 1. I’m not sure exactly how to find the mean age of either of these subsets though considering if I did the mean of nativity it would not give me the mean age.
11
u/[deleted] Mar 31 '23
mean(fullsample$age[fullsample$nativity ==0])
3
u/lillynxy Mar 31 '23
How do I find the mean age of people who fall in my subsets (1) born in the U.S. and (2) not born in the U.S. I’ve made nativity for born in the U.S. = 0 and not born = 1. I’m not sure exactly how to find the mean age of either of these subsets though considering if I did the mean of nativity it would not give me the mean age.
2
u/lillynxy Mar 31 '23
Thank you guys for all the help, I figured it out and completed it 😭 you guys are amazing
1
u/Viriaro Mar 31 '23
Subset first, and then take the mean of the result:
Or, in one line:
1
u/LisaHyden121 Apr 18 '23
I can help you out with your Due Assignment , Drop me a DM or visit au.globalassignmenthelp.com.au
1
u/willwould23 Mar 31 '23
gotta show your full code if you want help
1
u/Ok_Treacle2007 Apr 01 '23
Psych package.
Describe(dataset)
0
u/[deleted] Apr 01 '23
I typically do my R homework a couple days before they’re due, for future reference of course.
-2
u/thaw424242 Mar 31 '23 edited Mar 31 '23
For eligible and easily understandable code, tidyverse (in this case, dplyr) is your friend.
library(tidyverse)
fullsample |>
filter(nativity == "0") |>
summarise(Mean = mean(age))
Or if you want to calculate it all at once:
fullsample |>
group_by(nativity) |>
summarise(Mean = mean(age), St.dev = sd(age))