[R] creating character vector

Jim Lemon jim at bitwrit.com.au
Mon Mar 14 10:41:00 CET 2011


On 03/14/2011 08:29 PM, Maas James Dr (MED) wrote:
> Is there a way to convince R to create a character vector without using the quotes?
>
> This works
>
> ex1<-  c("first","second")
>
> but when I try this it doesn't
>
> ext<- as.character(c(first,second))
>
> it complains. I have many variables to put into character vectors so dispensing with the quotes would be useful.
>
Hi Jim,
If you are reading values in from a file, you can get character vectors 
like this:

<contents of file "charvec.txt">
Monday Tuesday Wednesday Thursday Friday Saturday

charvec<-unlist(read.table("charvec.txt",stringsAsFactors=FALSE))
is.character(charvec)

Jim



More information about the R-help mailing list