vendredi 30 janvier 2015

Conditional statement in R dataframe

I have dataframe df as below.



dput(df)
structure(list(X = c(1, 2, 5, 7, 8), Y = c(3, 5, 8, 7, 2), Z = c(2,
8, 7, 4, 3), R = c(6, 6, 6, 6, 66)), .Names = c("X", "Y", "Z",
"R"), row.names = c(NA, -5L), class = "data.frame")
df
class(df)


I have to modify df under two conditions. First: modify df so that it check minimum between X,Y,Z for each row and whichever is minimum get replaced with corresponding value of R. Second case: which is minimum between X,Y,Z,R in each row, it get replaced with maximum between X,Y,Z,and R and create a new df. How should i get that? I tried ifelse and if and else but could not get what i want.. Any help would be appreciated.


Aucun commentaire:

Enregistrer un commentaire