I'm trying to create a function that takes in a data frame and a value from the first column of the data frame. Let's call the value from the first column of the data frame "value1". This means the function should be in a form
Function <- function (data, value1)
If "value1" is found from the data, it should return "value1", the maximum value of the row the "value1" is in, and the column name of the maximum value.
If "value1" is not found, it should return "Check value".
What I've done so far:
value1 <- function(data) {
data[1]
}
Function <- function (data, "value1") {
if(any(value1 %in% data[[1]])) {
maxcol <- which.max(data[value1,])
print(paste(value1, data[maxcol,], data[maxcol, value1]))
} else {
print("Check value")}
}
I created "value1" separately because I didn't know how to do it otherwise.
My problem is that the function doesn't print the correct things when "value1" is found.
Aucun commentaire:
Enregistrer un commentaire