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

______________________________________________
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.

Reply via email to