Re: [R] creating character vector

From: peter dalgaard <pdalgd_at_gmail.com>
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: pd.mes_at_cbs.dk  Priv: PDalgd_at_gmail.com

______________________________________________
R-help_at_r-project.org mailing list
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.
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive