remove level from a list extract to a data fram

user2187202 picture user2187202 · May 27, 2013 · Viewed 7.3k times · Source

I have a data frame like this

    df <- data.frame(letters=letters[1:5], numbers=seq(1:5))

and lets say that I want to extram the first column into a list

firstColumn <- df[,1]

>  firstColumn[[1]]
[1] a
Levels: a b c d e

Problème is I want to remove the level to have a string

any help please ?

thanks

Answer

juba picture juba · May 27, 2013

Either define your variable as character from the beginning :

df <- data.frame(letters=letters[1:5], numbers=seq(1:5), stringsAsFactors=FALSE)

Or convert it afterwards :

firstColumn <- as.character(df[,1])