I have data similar to the below in a df. I wrote a function to convert it to time in minutes. 90 min 39 min 21 min 109 min 100 min 97 min 110 min 84 min 97 min 94 min 80 min 110 min 30 min 95 min 59 min 9 min 2 h 5 min 3 h 45 min 4h N/A NA 78 min 80 min 108 min 85 min 5 min 83 min
I wrote this function and keep getting the error missing value where True/False needed. I think I've taken care of the NA and N/A cases, but still get the error. What do I need to do to correct the function and eliminate the error?
myfunction <- function(x){
if (x=="N/A"){
x=NA
} else if(is.na(x)){
x=NA
}
x <- unlist(strsplit(x, " ", fixed=TRUE))
if(x[2]=='min'){
x<-as.numeric((x[1]))
}
if(!is.na(x)){
if (x[2]=='h'){
if (is.null(x[4])||is.na(x[4])){
x<-(as.numeric((x[1])))*60
}
if (x[4]=='min') {
x<-(as.numeric((x[1])))*60 + as.numeric((x[3]))
}
}
}
return(x)}
Aucun commentaire:
Enregistrer un commentaire