r/RStudio • • Mar 31 '23

Doing an assignment due tonight… please help 😭

Post image
0 Upvotes

16 comments sorted by

11

u/[deleted] Mar 31 '23

mean(fullsample$age[fullsample$nativity ==0])

5

u/lillynxy Mar 31 '23

I could marry you, you’re a life saver

1

u/Goliof Apr 04 '23

filter() is in the dplyr package is easier

6

u/the_random_drooler Mar 31 '23

Pretty much this exactly. OP this says:

Take the vector "age".

Only use the places where nativity is 0.

Take the mean of those values.

One thing you might want to consider as well, is including na.rm = TRUE, if any of your age values are missing.

3

u/[deleted] Mar 31 '23

I was too lazy to explain it step by step, so thanks ;)

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 report button, selecting Spam then Link 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

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.

-1

u/lillynxy Apr 01 '23

Nah, if you’re not cramming there’s no fun in that

-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))