Short version:
I do not understand the behaviour of as.character when trying to convert a single 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"
Maybe somebody could give me an explanation for the last 2 output lines and the correct approach? Thanks a lot.
Background/Purpose:
I want to use lre()
in order to detect consecutive occurrences of values in a row of a data frame (with columns of different data types).
Problem: lre()
requires a vector, vectors require a definite data type (integer, character, factor, ...). My idea here is to turn the data frame row into a character vector to avoid data loss through conversion.