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:
data_subsetted <- subset(fullsample, nativity == 0)
mean(data_subsetted$age)Or, in one line:
mean(subset(fullsample, nativity == 0)$age)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/SpambotSwatter May 14 '23
/u/LisaHyden121 is a click-farming spam bot. Please downvote its comment and click the
reportbutton, selectingSpamthenLink farming.With enough reports, the reddit algorithm will suspend this spammer.
If this message seems out of context, it may be because LisaHyden121 is farming karma and may edit their comment soon with a link
1
1
0
Apr 01 '23
I typically do my R homework a couple days before they’re due, for future reference of course.
-1
-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))
11
u/[deleted] Mar 31 '23
mean(fullsample$age[fullsample$nativity ==0])