[R] cbind in data.frame
charles-r-nospam at plessy.org
Mon Aug 25 08:09:42 CEST 2008
Le Sun, Aug 24, 2008 at 10:56:43PM -0700, Yuan Jian a écrit :
> when I used cbind to combine columns, some contents of columns has been replaced by
> number. in the script below, column should be aaa,bbb,ccc but I was given 1,2,3.
> but when I change the column to vector, it gave me correct contents. can you please
> tell me why?
> > d<-read.table("aaa.txt")
read.table converts characters to factors. Factors will be converted
to numbers by cbind, as in the following example:
> toto <- c("aaa","bbb","aaa")
 "aaa" "bbb" "aaa"
 aaa bbb aaa
Levels: aaa bbb
The 'as.is' or 'colClasses' option of read.table will help you to prevent the
conversion of characters to factors.
Have a nice day,
Tsurumi, Kanagawa, Japan
More information about the R-help