I'm trying to create a function that takes in a data frame and a column name in the data. If the column name is not found in the data, the function should return "check column name". If the column name is found, it should return "(column name) text here (row name) text here (max value of the column)".
What I've done so far is
Function <- function(data,col) {
data<-data[, col]
if(is.na(col)) {
print ("check column name")
} else {
print(paste(colnames(data), "text here", rownames(data), "text here", max(data))
}
}
but this won't work.
I think the problem is that is don't know how to define the "if column name is not found in data". I also tried
if(col==NA)
if(data==NA)
but they don't work either. I also am not sure how to print value, such as the row and column names, in the middle of text which the function should return when the column name is found in the data.
Aucun commentaire:
Enregistrer un commentaire