Finden des Maximalwerts für jede Zeile aus 3 Spalten in R
Ich muss den Maximalwert für jede Zeile aus 3 Spalten berechnen.
Eine Tabelle könnte sein:
x = c(1,2,3,4,5 )
y = c(2,3,3,1,1 )
z = c(4,3,2,1,1 )
df<-data.frame(x,y,z)
Ich benötige
x y z max
1 1 2 4 4
2 2 3 3 3
3 3 3 2 3
4 4 1 1 4
5 5 1 1 5
Ich habe es versucht
df$max<-max(x, y,z)
Aber ich bekomme:
x y z max
1 1 2 4 5
2 2 3 3 5
3 3 3 2 5
4 4 1 1 5
5 5 1 1 5
So, wie kann ich das richtig machen?