?rbind
Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Mar 24, 2016 at 9:49 PM, Hiroyuki Sato <hiroys...@gmail.com> wrote: > Hello members > > Question > > Could you tell me how to add ID 100, 104, 105 values with zero? > > 1, Source data > > > ID 100, 104 and 105 has no values. > > >> s > ID DATE VAR CODE > 1 101 20160301 1 PDT1 > 2 102 20160301 1 PDT2 > 3 103 20160301 1 PDT3 > 4 103 20160302 1 PDT3 > > s <- structure(list(ID = c(101L, 102L, 103L, 103L), DATE = c(20160301L, > 20160301L, 20160301L, 20160302L), VAR = c(1L, 1L, 1L, 1L), CODE = > structure(c(1L, > 2L, 3L, 3L), .Label = c("PDT1", "PDT2", "PDT3"), class = "factor")), .Names > = c("ID", > "DATE", "VAR", "CODE"), class = "data.frame", row.names = c(NA, > -4L)) > > src <- 100:106 > > > 2, Expect output > > ID PDT1 PDT2 PDT3 > 1 100 0 0 0 > 2 101 1 0 0 > 3 102 0 1 0 > 4 103 0 0 2 > 5 104 0 0 0 > 6 105 0 0 0 > > 3, Convert process. > > I can convert data "s" like following. > >> library(reshape2) >> dcast(s,ID ~ CODE, value.var="VAR",sum) > ID PDT1 PDT2 PDT3 > 1 101 1 0 0 > 2 102 0 1 0 > 3 103 0 0 2 > > Could you tell me how to add 100, 104, 105 values into convert results? > > > Regards. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.