I have two dataframes in R that were tab seperated .txt files y<-read.table("foo.txt", header=T) x<-read.table("foo.txt", header=T) these are set up like this: Datetime Temp 01/01/07 00:01 11.5 01/01/07 00:16 11.6 etc etc to 66000 rows in y and 33000 rows in x The two files overlap with the same data for a period of time but contain different values outside of these. Is there a way to merge these two data sets based on the shared date time column into one large dataset of ~90,000 lines. I want to eventually make this into a time series with frequency= 1/15. Thanks Stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Try this: x Datetime Temp 1 01/01/07 00:01 11.5 2 01/01/07 00:16 11.6 y Datetime Temp 1 01/01/07 00:01 10 2 01/01/07 00:16 3 merge(x, y, by="Datetime") Datetime Temp.x Temp.y 1 01/01/07 00:01 11.5 10 2 01/01/07 00:16 11.6 3 On 22/02/2008, stephen sefick <ssefick at gmail.com> wrote:> I have two dataframes in R that were tab seperated .txt files > > y<-read.table("foo.txt", header=T) > x<-read.table("foo.txt", header=T) > > these are set up like this: > > Datetime Temp > 01/01/07 00:01 11.5 > 01/01/07 00:16 11.6 > > etc etc to 66000 rows in y and 33000 rows in x > > The two files overlap with the same data for a period of time but > contain different values outside of these. Is there a way to merge > these two data sets based on the shared date time column into one > large dataset of ~90,000 lines. I want to eventually make this into a > time series with frequency= 1/15. > > Thanks > > Stephen > -- > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
You could do it with zoo: DF1 <- data.frame(Datetime = ISOdate(2000, 1:2, 1), Temp = 1:2) DF2 <- data.frame(Datetime = ISOdate(2000, 2:3, 1), Temp = 3:4) library(zoo) # convert to zoo z1 <- zoo(DF1[,2], DF1[,1]) z2 <- zoo(DF2[,2], DF2[,1]) # merge z <- merge(z1, z2, all = TRUE) # take rowmeans zz <- zoo(rowMeans(z, na.rm = TRUE), time(z)) # or DF3 <- data.frame(data = rowMeans(z, na.rm = TRUE), Time = time(z)) On Fri, Feb 22, 2008 at 1:36 PM, stephen sefick <ssefick at gmail.com> wrote:> I have two dataframes in R that were tab seperated .txt files > > y<-read.table("foo.txt", header=T) > x<-read.table("foo.txt", header=T) > > these are set up like this: > > Datetime Temp > 01/01/07 00:01 11.5 > 01/01/07 00:16 11.6 > > etc etc to 66000 rows in y and 33000 rows in x > > The two files overlap with the same data for a period of time but > contain different values outside of these. Is there a way to merge > these two data sets based on the shared date time column into one > large dataset of ~90,000 lines. I want to eventually make this into a > time series with frequency= 1/15. > > Thanks > > Stephen > -- > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > ______________________________________________ > 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. >
stephen sefick wrote:> I have two dataframes in R that were tab seperated .txt files > > y<-read.table("foo.txt", header=T) > x<-read.table("foo.txt", header=T) > > these are set up like this: > > Datetime Temp > 01/01/07 00:01 11.5 > 01/01/07 00:16 11.6 > > etc etc to 66000 rows in y and 33000 rows in x > > The two files overlap with the same data for a period of time but > contain different values outside of these. Is there a way to merge > these two data sets based on the shared date time column into one > large dataset of ~90,000 lines. I want to eventually make this into a > time series with frequency= 1/15.Have you tried ?merge. Uwe Ligges> Thanks > > Stephen