[R] Simple averaging question
I have the following data: http://i.imagehost.org/0650/Untitled2.jpg How would i average, say the 5th and the 8th entries? Thanks in advance -- View this message in context: http://n4.nabble.com/Simple-averaging-question-tp1009086p1009086.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Simple averaging question
Assuming the data frame is named X: mean(X[c(5,8), Time]) See ?'[' for details. -Ista On Thu, Jan 7, 2010 at 1:20 PM, lse1986 sam_eden1...@yahoo.co.uk wrote: I have the following data: http://i.imagehost.org/0650/Untitled2.jpg How would i average, say the 5th and the 8th entries? Thanks in advance -- View this message in context: http://n4.nabble.com/Simple-averaging-question-tp1009086p1009086.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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.
[R] simple averaging question?
Hi all, Suppose I have a column vector of 600 measurements taken in 1s intervals. What I want is a new vector with the averages for each min (so there would be 10 entries). Is there an efficient way to do this? Ive been doing it with a for loop but something tells me there is a simple command that is more efficient. Jeff Internal Virus Database is out-of-date. Checked by AVG Free Edition. 3:09 PM [[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.
Re: [R] simple averaging question?
Jeff Miller wrote: Hi all, Suppose I have a column vector of 600 measurements taken in 1s intervals. What I want is a new vector with the averages for each min (so there would be 10 entries). Is there an efficient way to do this? I’ve been doing it with a ‘for’ loop but something tells me there is a simple command that is more efficient. How about something like this? y - runif(600) df - data.frame(minute = rep(1:10, each=60), y = y) with(df, tapply(y, minute, mean)) 1 2 3 4 5 0.4664301 0.4622071 0.5159511 0.4744836 0.5282750 6 7 8 910 0.4670941 0.5091410 0.4648349 0.5227221 0.5251926 Jeff Internal Virus Database is out-of-date. Checked by AVG Free Edition. 3:09 PM [[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. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ 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.
Re: [R] simple averaging question?
Moshe, Ted, Chuck, All THREE approaches worked fine for me. Thank you! Sincerely, Jeff Miller Internal Virus Database is out-of-date. Checked by AVG Free Edition. 3:09 PM ---BeginMessage--- Jeff Miller wrote: Hi all, Suppose I have a column vector of 600 measurements taken in 1s intervals. What I want is a new vector with the averages for each min (so there would be 10 entries). Is there an efficient way to do this? I’ve been doing it with a ‘for’ loop but something tells me there is a simple command that is more efficient. How about something like this? y - runif(600) df - data.frame(minute = rep(1:10, each=60), y = y) with(df, tapply(y, minute, mean)) 1 2 3 4 5 0.4664301 0.4622071 0.5159511 0.4744836 0.5282750 6 7 8 910 0.4670941 0.5091410 0.4648349 0.5227221 0.5251926 Jeff Internal Virus Database is out-of-date. Checked by AVG Free Edition. 3:09 PM [[alternative HTML version deleted]] __ R-help@r-project.org mailing list [1]https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide [2]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 Internal Virus Database is out-of-date. Checked by AVG Free Edition. 10/21/07 3:09 PM References 1. https://stat.ethz.ch/mailman/listinfo/r-help 2. http://www.R-project.org/posting-guide.html ---End Message--- __ 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.