[R] Splitting on metacharacters
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Tue Mar 28 20:08:30 CEST 2017
What you are seeing when printing depends on how you do it (and it can be confusing). Try this, type the following lines exactly (or copy and paste) and carefully study the results. In particular, compare the results of cat(s,'\n') with the results of strsplit(s, '"') .
s <- "{\"Q0\":\"37\",\"Q1\":\"f\"}"
s
cat(s,'\n')
'"' # single quote, double quote, single quote
strsplit(s, '"')
Hope this is helpful,
Dan
Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Patzelt,
> Edward
> Sent: Tuesday, March 28, 2017 9:50 AM
> To: R-help at r-project.org
> Subject: [R] Splitting on metacharacters
>
> Hi R-help,
>
> I would like to:
>
> Extract the "26" and "f" from the following string (i.e. age and gender).
> I've tried a bunch of strsplit, grep, etc. Please help!
>
> *"{\"Q0\":\"37\",\"Q1\":\"f\"}"*
>
>
> Thanks,
>
> Edward
>
> --
> Edward H Patzelt | Clinical Science PhD Student
> Psychology | Harvard University
> *Computational Cognitive Neuroscience Laboratory
> <http://gershmanlab.webfactional.com/>*
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list