Skip to content

Operating on each row of data frame

4 messages · Pete B, Stephan Kolassa, Abhishek Pratap

#
Look at the apply function
?apply

x = data.frame(x1=c(1,2,3,4,5),x2=c(2,4,6,8,10),x3=c(1,3,5,7,9))
x$x5=apply(x,1,mean)
x$x6=apply(x,1,sd)

print(x)
Abhishek Pratap wrote:

  
    
#
Hi,

does this do what you want?

d <- cbind(d,apply(d[,c(2,3,4)],1,mean),apply(d[,c(2,3,4)],1,sd))

HTH,
Stephan


Abhishek Pratap schrieb: