Hi everyone,
I'm trying to write an ifelse code to convert certain numbers based on a substring:
as.numeric(substring(check$a_ampicillin_mic,2))+1 <- this seems to work
but
as.numeric(substring(astresult[micvec],2))+1 <- this doesn't work and gives me the error "Error: Must subset columns with a valid subscript vector.
x Subscript micvec has the wrong type `tbl_df<
a_amocla_mic : character ... etc"?
Does anybody know why? I want to use the second method because I'm trying to convert several columns in a dataframe.
The codes I used are as follows (the 1st one works, 2nd one gives me the error)
-
check$a_ampicillin_mic<- ifelse(grepl(">",check$a_ampicillin_mic),
as.numeric(substring(check$a_ampicillin_mic,2))+1,
check$a_ampicillin_mic)
-
micvec <- select(astresult, contains("_mic"))
astresult[micvec] <-
for (i in astresult[micvec]){
ifelse(grepl(">",astresult[micvec]),
as.numeric(substring(astresult[micvec],2))+1,
astresult[micvec])
}