Stefano Sofia
2008-Apr-19 13:04 UTC
[R] Query: how to group data by months from a text file
Dear R-users, I have to deal with (txt) files of the form 10092007 24.62 24.31 24.90 11092007 19.20 23.17 22.10 13092007 24.71 27.33 23.10 14092007 27.33 27.90 24.10 15092007 28.22 28.55 24.30 16092007 28.53 29.24 27.40 17092007 24.19 30.64 26.80 18092007 22.60 20.62 28.40 19092007 18.89 21.70 14.70 20092007 21.27 22.92 17.30 21092007 22.38 24.72 18.80 22092007 23.94 24.73 20.40 23092007 25.33 25.12 22.60 24092007 24.91 22.46 21.40 25092007 23.52 25.00 21.70 26092007 20.50 22.29 18.80 ... where in the first column there is the date (DDMMYYYY), in the last three columns data. I should divide these data by months (example:Jan07, Feb07, ..., Dec07, Jan08, ...), where the start and the end can change depending on the file. Could somebody give me some good hints about it? thank you Stefano [[alternative HTML version deleted]]
Gabor Grothendieck
2008-Apr-19 13:14 UTC
[R] Query: how to group data by months from a text file
Lines <- "10092007 24.62 24.31 24.90 11092007 19.20 23.17 22.10 13092007 24.71 27.33 23.10 14092007 27.33 27.90 24.10 15092007 28.22 28.55 24.30 16092007 28.53 29.24 27.40 17092007 24.19 30.64 26.80 18092007 22.60 20.62 28.40 19092007 18.89 21.70 14.70 20092007 21.27 22.92 17.30 21092007 22.38 24.72 18.80 22092007 23.94 24.73 20.40 23092007 25.33 25.12 22.60 24092007 24.91 22.46 21.40 25092007 23.52 25.00 21.70 26092007 20.50 22.29 18.80 " library(zoo) z <- read.zoo(textConnection(Lines), format = "%d%m%Y") aggregate(z, as.yearmon, mean) See the three vignettes and help files: vignette(package = "zoo") On Sat, Apr 19, 2008 at 9:04 AM, Stefano Sofia <stefano.sofia at regione.marche.it> wrote:> Dear R-users, > I have to deal with (txt) files of the form > > 10092007 24.62 24.31 24.90 > 11092007 19.20 23.17 22.10 > 13092007 24.71 27.33 23.10 > 14092007 27.33 27.90 24.10 > 15092007 28.22 28.55 24.30 > 16092007 28.53 29.24 27.40 > 17092007 24.19 30.64 26.80 > 18092007 22.60 20.62 28.40 > 19092007 18.89 21.70 14.70 > 20092007 21.27 22.92 17.30 > 21092007 22.38 24.72 18.80 > 22092007 23.94 24.73 20.40 > 23092007 25.33 25.12 22.60 > 24092007 24.91 22.46 21.40 > 25092007 23.52 25.00 21.70 > 26092007 20.50 22.29 18.80 > ... > > where in the first column there is the date (DDMMYYYY), in the last three columns data. > I should divide these data by months (example:Jan07, Feb07, ..., Dec07, Jan08, ...), where the start and the end can change depending on the file. > Could somebody give me some good hints about it? > > thank you > Stefano > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >