Hi Rnewb, Take a look at ?"%in%" .
HTH, Jorge On Sun, Nov 29, 2009 at 11:06 PM, Rnewb <> wrote: > > i have a data frame and a numeric vector indexed as a subset of the rows in > the data.frame. what command can i use to assign the values in the vector > to the appropriate rows of the data.frame? here's my failed attempt. what > i would want is data[1,'z'] == 2, data[5,'z'] == -4, data[8,'z'] == -5, > data[9,'z'] == 5, and for the other values of 'z' to remain 0. > > > data > x y z > 1 -6 4 0 > 2 -3 19 0 > 3 15 40 0 > 4 0 17 0 > 5 1 12 0 > 6 17 45 0 > 7 4 19 0 > 8 -13 -16 0 > 9 -7 5 0 > 10 -5 22 0 > > vec > 1 5 8 9 > 2 -4 -5 5 > > data['z']=vec > Error in `[<-.data.frame`(`*tmp*`, "z", value = c(2, -4, -5, 5)) : > replacement has 4 rows, data has 10 > > > > thanks, > Rnewb > -- > View this message in context: > http://n4.nabble.com/updating-subset-of-data-frame-tp931051p931051.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 > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ 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.