Fantastic, thanks alot for that! Take care.
Adam. Date: Sat, 30 Mar 2013 01:14:49 -0700 From: ml-node+s789695n466289...@n4.nabble.com To: english.fel...@hotmail.com Subject: Re: Dataframe manipulation Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",stringsAsFactors=FALSE) str(dat1) #'data.frame': 102 obs. of 5 variables: # $ species : chr "B. barbastrellus" "E. nilssonii" "H. savii" "M. alcathoe" ... # $ period : chr "dusk" "dusk" "dusk" "dusk" ... # $ treatment: chr "control" "control" "control" "control" ... # $ no.files : int 16 1 9 13 1 49 6 3 4 0 ... # $ expected : logi NA NA NA NA NA NA ... dat2<-within(dat1,{expected<-ave(no.files,species,treatment,FUN=mean)}) head(dat2) # species period treatment no.files expected #1 B. barbastrellus dusk control 16 14.333333 #2 E. nilssonii dusk control 1 1.000000 #3 H. savii dusk control 9 4.666667 #4 M. alcathoe dusk control 13 13.333333 #5 M. bechsteinii dusk control 1 5.666667 #6 M. brandtii dusk control 49 63.000000 A.K. ________________________________ From: adam bosworth <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Friday, March 29, 2013 2:29 PM Subject: RE: Dataframe manipulation Hey, Thanks for the responce. I'm not sure if you messaged me on the forum or emailed me, but the only way I could get back to you was email, so hope that's alright. I've attached part of the dataset into a csv file for you to look at. in cell E2 I've given an example output I'd like in the dataframe, by summing values of '16', '25' and '2' from cells D2, D12 and D22 respectively and then dividing this by 3. [[elided Hotmail spam]] > Date: Fri, 29 Mar 2013 10:24:31 -0700 > From: [hidden email] > To: [hidden email] > Subject: Dataframe manipulation > > HI, > Is it possible to post a small example dataset and also the output dataset > you wanted? In that way, it will be much more easier to understand what you > meant. > <quote author='englishfellow'> > New to R and struggling with dataframe commands, any help will be much > appreshiated. > > I have an existing dataframe call it 'df' with 4 colums and I have added a > 5th column which I need to fill, the conditions of which are as follows: > > for each row in column 5, I need it to look at column 1 and find all data > which are equal to that present in that row. I then need to look through > those rows in column 3 and again, find rows where the data are equal to the > row in question, after it has found these rows I need it to look in column 4 > for values, add them up and divide the sum by 3. > > I tried to explain that as best I could, and I can go into more detail if it > helps clarify what I'm after. > > But like I said, any help would be great. > > Cheers. > > > </quote> > Quoted from: > http://r.789695.n4.nabble.com/Dataframe-manipulation-tp4662844.html ______________________________________________ [hidden email] 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Dataframe-manipulation-tp4662844p4662890.html To unsubscribe from Dataframe manipulation, click here. NAML -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-manipulation-tp4662844p4662894.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] ______________________________________________ R-help@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.