Short version:
I do not understand the behavior of as.character when trying to convert one row of a data frame to a character vector.
> mydf <- data.frame("myvar1"=c("mystring","2"),"myvar2"=c("mystring","3")) > mydf # nice! myvar1 myvar2 1 mystring mystring 2 2 3 > as.character(mydf[1,]) [1] "2" "2" > as.character(as.vector(mydf[1,]) ) [1] "2" "2"
Can someone please give me an explanation for the last two output lines and the correct approach? Many thanks.
Background / Purpose:
I want to use lre() to detect successive occurrences of values ββin a row of a data frame (with columns of different data types).
Task: lre() requires a vector, vectors require a certain type of data (integer, character, coefficient, ...). My idea is to turn a data frame string into a character vector to avoid data loss by conversion.
string type-conversion vector r
nilsole
source share