[R] Re place many rows in a table with new rows in one step
David Winsemius
dwinsemius at comcast.net
Fri Oct 9 19:40:04 CEST 2009
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 columns
replace() 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
More information about the R-help
mailing list