Re: [R] Replace value in a matrix according to a list with a list of value .

2014-01-09 Thread arun
Hi, You may also try: vec1 <- (seq(nrow(mm))-1)*ncol(mm) pos2 <- unlist(mapply("+",pos,vec1)) mm1 <- t(mm) mm1[pos2] <- unlist(gty) identical(res,t(mm1)) #[1] TRUE A.K. On Thursday, January 9, 2014 9:40 AM, arun wrote: Hi, Try: res <-  do.call(rbind,lapply(seq_len(nrow(mm)),function(i) {x1

Re: [R] Replace value in a matrix according to a list with a list of value .

2014-01-09 Thread arun
Hi, Try: res <-  do.call(rbind,lapply(seq_len(nrow(mm)),function(i) {x1 <- mm[i,]; x1[pos[[i]]] <- gty[[i]]; x1})) A.K. On Thursday, January 9, 2014 9:28 AM, Mohammad Tanvir Ahamed wrote: Hi there !! I have a matrix like  > mm       [,1] [,2] [,3]  [1,]    1   11   21  [2,]    2   12   22

Re: [R] Replace value in a matrix according to a list with a list of value .

2014-01-09 Thread Duncan Murdoch
On 09/01/2014 9:25 AM, Mohammad Tanvir Ahamed wrote: Hi there !! I have a matrix like > mm [,1] [,2] [,3] [1,]1 11 21 [2,]2 12 22 [3,]3 13 23 I have a list of position index like > pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values l

[R] Replace value in a matrix according to a list with a list of value .

2014-01-09 Thread Mohammad Tanvir Ahamed
Hi there !! I have a matrix like  > mm       [,1] [,2] [,3]  [1,]    1   11   21  [2,]    2   12   22  [3,]    3   13   23 I have a list of position index like  > pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values like > gty $v1  9  3  $v2  4  8  $v3  7  4  1