Re: [R] creating character vector

From: peter dalgaard <>
Date: Mon, 14 Mar 2011 21:37:23 +0100

On Mar 14, 2011, at 16:32 , Allan Engelhardt wrote:

> You could try
> scan(what=character(0), sep=",", file=textConnection("first,second,third"))
> but better to put the strings in a file (say, strings.txt), one per line, and read it using
> scan("strings.txt", what=character(0), sep="\n")

Also, things like this come in handy at times:

## From dept. of slightly dirty trix:
txt <- "fmffmfmfmfmfmmmmfmmmffmff"
lizards$sex <- factor(unlist(strsplit(txt,"")),levels=c("m","f"))

It is easily generalized to include a delimiter.

Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email:  Priv:

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 14 Mar 2011 - 20:42:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 20:50:21 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive