Of course you could have created them as character vectors in the first
place:
dfx <- data.frame(
group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
sex = sample(c("M", "F"), size = 29, replace = TRUE),
age = runif(n = 29, min = 18, max = 54),
stringsAsFactors=FALSE
)
But if that is no
Try as.character like the following shows.
> dfx <- data.frame(
+ group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
+ sex = sample(c("M", "F"), size = 29, replace = TRUE),
+ age = runif(n = 29, min = 18, max = 54))
> dfx
group sex age
1 A M 41.35554346
2 A F 47.7
Dear R-List,
#I have a df with the first two cols formatted as factor.
dfx <- data.frame(
group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
sex = sample(c("M", "F"), size = 29, replace = TRUE),
age = runif(n = 29, min = 18, max = 54))
# now I want to format both factor VARs as character
# I
3 matches
Mail list logo