Dear All, I am trying to create a empty structure that I want to fill gradually through the code. I want to use something like rbind to create the basic structure first. I am looking for a possibility to do an rbind where the columns names dont match fully (but the missing columns can be defaulted to either zero or n/a) (my actual data has a lot of columns). Please see the data frames below I have the following data frame that is filled> dput(d)structure(list(type = structure(1:9, .Label = c("test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9" ), class = "factor"), meter = c(37.25122438, 58.65845732, 63.47108421, 94.76085162, 13.75013867, 8.520664878, 79.74623167, 62.16109819, 20.47806657), degree = c(2.884440333, 74.94067898, 32.64251152, 83.24820274, 58.36084794, 12.64490368, 4.428796741, 32.12824213, 97.83710088)), .Names = c("type", "meter", "degree"), class "data.frame", row.names = c(NA, -9L)) To the above data I want to append the following data to create an empty structure for the new data> dput(dNewTests)structure(list(type = structure(1:9, .Label = c("test14", "test15", "test16", "test17", "test18", "test19", "test20", "test21", "test22" ), class = "factor")), .Names = "type", class = "data.frame", row.names = c(NA, -9L)) rbind obviously throws the following error: rbind(d, dNewTests) Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match Any way that I can default the missing columns to NA or some default value like zero? Also, I tried to go through the archives and tried merge_all. What am I doing wrong wih the code below ? require(reshape) merge_all(d, dNewTests,by="type") Error in fix.by(by.x, x) : 'by' must specify column(s) as numbers, names or logical Thanks, Santosh
Sender: r-help-bounces at r-project.org On-Behalf-Of: santosh.srinivas at gmail.com Subject: [R] Flexible rbind Message-Id: <AANLkTimNeoFi+nDx+xMvHR3Uw3PPyGkvTGKvBMZvAXxq at mail.gmail.com> Recipient: simon.rees at barclayscapital.com _______________________________________________ e at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. _______________________________________________ -------------- next part -------------- An embedded message was scrubbed... From: Santosh Srinivas <santosh.srinivas at gmail.com> Subject: [R] Flexible rbind Date: Thu, 17 Mar 2011 13:03:21 +0530 Size: 6876 URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110317/a5ec7431/attachment.mht>
Sender: r-help-bounces at r-project.org On-Behalf-Of: santosh.srinivas at gmail.com Subject: [R] Flexible rbind Message-Id: <AANLkTimNeoFi+nDx+xMvHR3Uw3PPyGkvTGKvBMZvAXxq at mail.gmail.com> Recipient: killian.doorley at barclayscapital.com _______________________________________________ e at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. _______________________________________________ -------------- next part -------------- An embedded message was scrubbed... From: Santosh Srinivas <santosh.srinivas at gmail.com> Subject: [R] Flexible rbind Date: Thu, 17 Mar 2011 13:03:21 +0530 Size: 6892 URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110317/fc369a50/attachment.mht>
Hi Santosh, May be you looking at something like this merge(d,dNewTests,by="type",all=TRUE) On Thu, Mar 17, 2011 at 1:03 PM, Santosh Srinivas < santosh.srinivas@gmail.com> wrote:> Dear All, > > I am trying to create a empty structure that I want to fill gradually > through the code. > I want to use something like rbind to create the basic structure first. > > I am looking for a possibility to do an rbind where the columns names > dont match fully (but the missing columns can be defaulted to either > zero or n/a) (my actual data has a lot of columns). > Please see the data frames below > > I have the following data frame that is filled > > dput(d) > structure(list(type = structure(1:9, .Label = c("test1", "test2", > "test3", "test4", "test5", "test6", "test7", "test8", "test9" > ), class = "factor"), meter = c(37.25122438, 58.65845732, 63.47108421, > 94.76085162, 13.75013867, 8.520664878, 79.74623167, 62.16109819, > 20.47806657), degree = c(2.884440333, 74.94067898, 32.64251152, > 83.24820274, 58.36084794, 12.64490368, 4.428796741, 32.12824213, > 97.83710088)), .Names = c("type", "meter", "degree"), class > "data.frame", row.names = c(NA, > -9L)) > > To the above data I want to append the following data to create an > empty structure for the new data > > dput(dNewTests) > structure(list(type = structure(1:9, .Label = c("test14", "test15", > "test16", "test17", "test18", "test19", "test20", "test21", "test22" > ), class = "factor")), .Names = "type", class = "data.frame", row.names > c(NA, > -9L)) > > rbind obviously throws the following error: > > rbind(d, dNewTests) > Error in rbind(deparse.level, ...) : > numbers of columns of arguments do not match > > Any way that I can default the missing columns to NA or some default > value like zero? > > Also, I tried to go through the archives and tried merge_all. What am > I doing wrong wih the code below ? > > require(reshape) > merge_all(d, dNewTests,by="type") > > Error in fix.by(by.x, x) : > 'by' must specify column(s) as numbers, names or logical > > > Thanks, > Santosh > > ______________________________________________ > 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. >[[alternative HTML version deleted]]