[R] another very simple loop question
Petr Pikal
petr.pikal at precheza.cz
Fri Apr 14 10:28:38 CEST 2006
Hi
What about some example data? I presume you could use some
apply, tapply, aggregate or similar function but without knowing what
you **really** want to do and how your previous attempts failed it is
hard to give any definite answer.
e.g.
mydf<-data.frame(year=sample(1:4,100,rep=T),
student=sample(letters[1:4],100, rep=T), result=runif(100))
aggregate(mydf$result,list(year=mydf$year,student=mydf$student),
mean)
year student x
1 1 a 0.4026579
2 2 a 0.4690311
...
15 3 d 0.5316301
16 4 d 0.4401949
>
HTH
Petr
On 14 Apr 2006 at 0:09, Brian Quinif wrote:
Date sent: Fri, 14 Apr 2006 00:09:32 -0400
From: "Brian Quinif" <bquinif at gmail.com>
To: r-help at stat.math.ethz.ch
Subject: [R] another very simple loop question
> I have a dataset with 4 years of students, and normally I want to
> estimate things using each individual year, so I have a for loop as
> follows
>
> for (i in 1:4){}
>
> However, the only way I know how to calculate estimates using all four
> years of data is to put the estimations outside of the loop. Is there
> anyway to make a for loop that uses all four years at once, then uses
> each individual year?
>
> Thanks,
>
> BQ
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list