Use as.data.frame
with stringsAsFactors = FALSE
Arguments
- ...
passed to
as.data.frame
Examples
data_matrix <- matrix(LETTERS[1:6], nrow = 2)
# as.data.frame() by default converts character to factor
str(as.data.frame(data_matrix))
#> 'data.frame': 2 obs. of 3 variables:
#> $ V1: chr "A" "B"
#> $ V2: chr "C" "D"
#> $ V3: chr "E" "F"
# asNoFactorDataFrame keeps character as character
str(asNoFactorDataFrame(data_matrix))
#> 'data.frame': 2 obs. of 3 variables:
#> $ V1: chr "A" "B"
#> $ V2: chr "C" "D"
#> $ V3: chr "E" "F"