g] on behalf of
arun [smartpink...@yahoo.com]
Sent: Tuesday, November 13, 2012 15:25
To: Haris Rhrlp
Cc: R help
Subject: Re: [R] multiply each row in a matrix with the help of the for loop
HI,
May be this helps:
list1<-lapply(lapply(1:3,function(i) {aa[1:i,,i]<-a[1:i,]*-1
return(aa[,,i])})
HI,
May be this helps:
list1<-lapply(lapply(1:3,function(i) {aa[1:i,,i]<-a[1:i,]*-1
return(aa[,,i])}),function(x) apply(x,2,function(i) ifelse(i==0,1,x)))
res<-array(unlist(list1),dim=c(nrow(list1[[1]]),ncol(list1[[1]]),length(list1)))
res
#, , 1
#
# [,1] [,2] [,3]
#[1,] -1 -1 -1
#[2
2 matches
Mail list logo