[R] "Conditional" average
Christopher W. Ryan
cryan at binghamton.edu
Thu Apr 26 05:32:56 CEST 2012
I think this will accomplish what you describe:
dd <- data.frame(id=c(1:6), age76=c(25, 27, 30, 82, 20, 25),
Wage76=c(102456, 15432, 12340, 6, 20000, 15000), Grade76=c(12, 15, 16,
88, 16, 12), Black=c(1, 0, 1, 0, 1, 1), imigrt=c(0, 1, 1, 0, 1, 1))
dd
dd.sub <- subset(dd, Grade76 %in% c(12,15,16))
dd.sub
#aggregate and summaryBy accomplish similar thing
aggregate(data=dd.sub, Wage76 ~ age76, FUN=mean)
library(doBy) #lattice gets loaded too
summaryBy(data=dd.sub, Wage76 ~ age76)
dd.means <- aggregate(data=dd.sub, Wage76 ~ age76, FUN=mean)
xyplot(data=dd.means, Wage76 ~ age76) # lattice already loaded
--Chris Ryan
kebrab67 wrote:
> id age76 Wage76 Grade76 Black immigrt. ...
> 1 25 102456 12 1 0
> 2 27 15432 15 0 1
> 3 30 12340 16 1 1
>
> Then I have lots of data variables 100 for 5000 individuals nearly. What I
> wanted is to discriminated by age and education level (age is years only and
> grade is years in educational system and wage is salary only no rational
> numbers here)
> I want to have for people of education level 10 12 16, the average wage for
> age 15, and then the same for age 16, and the same for age 17 and so on...
> Once i have these average I plot (age vs average salary) to see the
> "distribution in average"
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Conditional-average-tp4585313p4586691.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list