[R] conditional mean between two data frames with different levels
albechan
alberto.casetta at satt.biz
Thu Nov 18 18:17:55 CET 2010
Thank you very much Josh, I guess you`re right.
So this is an example:
data frame 1 has 2 columns and 10 rows. The first column is "score" a
variable indicating the number of goals scored by a football team
score<-c(1,2,0,2,1,1,3,2,1,0), column 2 contains the football "teams " where
teams<-c(a,b,c,d,e,a,b,c,d,e).
Data frame 2 has the following variables: score<-c(2,3,1,0,0,0,4,2,1,2) and
"teams"<-c(b,c,d,e,f,b,c,d,e,f).
What I need is to create a vector "alfa"<-numeric(10) where the first
element contains the mean of the number of goals scored by team b in the
previous season, the second element contains the mean of the number of goals
scored by team c in the previous season and so on. In correspondance of team
f, the average of the whole score vector of the previous season.
alfa should be (2.5, 1, 1.5, 0.5, 1.3, 2.5, 1, 1.5, 0.5, 1.3)
The problem arises because "f" doesnt appear in the first data frame as it
replaced "a".
Hope the issue is more understandable now.
Thanks a lot!
alberto
--
View this message in context: http://r.789695.n4.nabble.com/conditional-mean-between-two-data-frames-with-different-levels-tp3049010p3049171.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list