knavero
2012-Apr-04 03:57 UTC
[R] Trying to merge new data set to bottom of old data set. Both are zoo objects.
Here is the data I'm working with: http://r.789695.n4.nabble.com/file/n4530888/new.txt new.txt http://r.789695.n4.nabble.com/file/n4530888/old.txt old.txt My code is here: http://pastebin.com/9jjs6Ahr I'm looking for away to simply attach the new.txt to the bottom of old.txt through R, else I'll just throw it in Excel to do some preprocessing. I've looked into using merge, cbind, concatenate, and rbind. However, I'm running into problems where the 2012 data keeps ending up on top before the 2010 and 2011 data or the function just adds more extra columns to the right side. Is there a simple method of doing this? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4530888.html Sent from the R help mailing list archive at Nabble.com.
knavero
2012-Apr-04 05:47 UTC
[R] Trying to merge new data set to bottom of old data set. Both are zoo objects.
Here's a case where it doesn't work. Again, the problem is that when I use the rbind or concatenate functions, the 2012 data set seems to go ahead of the 2010 and 2011 portions of the data set. The problem seems dependent on the text files I read in: http://r.789695.n4.nabble.com/file/n4531011/old.txt old.txt http://r.789695.n4.nabble.com/file/n4531011/new.txt new.txt using this code: http://pastebin.com/8W6KaaPQ In a case where it works, and the data seemed to be in the right order, I read in a different old.txt named old1.txt and somehow it seemed to work. The contents and format were similar to that of new.txt where there was 18 columns with the same headers. Here are the files to use: http://r.789695.n4.nabble.com/file/n4531011/old1.txt old1.txt http://r.789695.n4.nabble.com/file/n4531011/new.txt new.txt using this code: http://pastebin.com/6iNF5bPd That should clarify the issue I'm having. Let me know if a dput is necessary here. However all the vectors and vector modes seem to check out okay. -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4531011.html Sent from the R help mailing list archive at Nabble.com.
Ashish Agarwal
2012-Apr-04 09:04 UTC
[R] Trying to merge new data set to bottom of old data set. Both are zoo objects.
It is unclear what the problem is. Does following code solve your append problem? fmt = "%m/%d/%Y %H:%M" fname <- "new.txt" #records = 2904 newfile <- read.csv(fname, header = TRUE, sep = ",", skip=0, colClasses = c(rep("character",2), rep("numeric", 16)) ) newfile.comb <- cbind(newfile[2], newfile[3]) fname <- "old.txt" #records = 73768 oldfile <- read.table(fname, header = FALSE, sep = "\t", dec = ".", colClasses = c("character","numeric","NULL"), skip = 0) names(oldfile)[1] <- names(newfile)[2] names(oldfile)[2] <- names(newfile)[3] combo.file = rbind(oldfile,newfile.comb) #records = 76672 edit(combo.file) AA On Wed, Apr 4, 2012 at 9:27 AM, knavero <knavero@gmail.com> wrote:> Here is the data I'm working with: > > http://r.789695.n4.nabble.com/file/n4530888/new.txt new.txt > > http://r.789695.n4.nabble.com/file/n4530888/old.txt old.txt > > My code is here: > > http://pastebin.com/9jjs6Ahr > > I'm looking for away to simply attach the new.txt to the bottom of old.txt > through R, else I'll just throw it in Excel to do some preprocessing. I've > looked into using merge, cbind, concatenate, and rbind. However, I'm > running > into problems where the 2012 data keeps ending up on top before the 2010 > and > 2011 data or the function just adds more extra columns to the right side. > Is > there a simple method of doing this? Thanks. > > -- > View this message in context: > http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4530888.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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]