Zhen Lin
2009-Oct-09 10:42 UTC
[R] Re place many rows in a table with new rows in one step
I tried this: (c is the column vector with indices of those rows I want to replace) table[c,]<-replace(table[c,],c,newRows) but it does not work and the error is: new columns would leave holes after existing columns Can anyone help please? Thanks -- View this message in context: http://www.nabble.com/Replace-many-rows-in-a-table-with-new-rows-in-one-step-tp25819016p25819016.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2009-Oct-09 17:40 UTC
[R] Re place many rows in a table with new rows in one step
On Oct 9, 2009, at 6:42 AM, Zhen Lin wrote:> > I tried this: > (c is the column vector with indices of those rows I want to replace) > > table[c,]<-replace(table[c,],c,newRows) > > but it does not work and the error is: > new columns would leave holes after existing columnsreplace() is supposed to work on vectors, but if you have a table object then that might be better manipulated with indexing approaches. Try making up a small table object and they working on it. > table1 <- table(sample(LETTERS[1:5], 10, replace=T), sample(letters[1:5], 10, replace=T)) > table1 a b c d A 1 0 1 2 B 0 1 0 0 C 0 1 0 1 D 0 0 0 1 E 0 1 0 1 > table1[2,] <- c(1,1,1,1) > table1 a b c d A 1 0 1 2 B 1 1 1 1 C 0 1 0 1 D 0 0 0 1 E 0 1 0 1 -- David Winsemius, MD Heritage Laboratories West Hartford, CT