I need to calculate the maximum value for each row among 3 columns.
A table could be:
x = c(1,2,3,4,5 ) y = c(2,3,3,1,1 ) z = c(4,3,2,1,1 ) df<
You can use the apply function for this like so:
apply
df$max<-apply(X=df, MARGIN=1, FUN=max)
The MARGIN=1 argument indicated that for every row in X you wish to apply the function in FUN. If you use MARGIN=2 it will be by column or MARGIN=c(1,2) it will be both rows and columns.
MARGIN=1
X
FUN
MARGIN=2
c(1,2)