> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help@r-project.org> wrote:
> 
> This is not  serious problem but I just wonder if someone can explain what is 
> happening.
> The same command within a dataframe is giving me a factor and as a plain 
> vector is giving me a character.  It's probably something simple that I have 
> read and forgotten but I thought I'd ask.
> Thanks
> 
> #================================================
> dat1 <- data.frame(aa = letters[1:10])
> str(dat1)
> data.frame':    10 obs. of  1 variable:
> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 
> 8 9 10#=============================================================
> bb = letters[1:10]
> str(bb)
> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
> #==============================================================
> 


See the 'stringsAsFactors' argument in ?data.frame.

dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE)

> str(dat1)
'data.frame':   10 obs. of  1 variable:
 $ aa: chr  "a" "b" "c" "d" ...


Regards,

Marc Schwartz

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to