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:[email protected]] On Behalf Of Patzelt,
> Edward
> Sent: Tuesday, March 28, 2017 9:50 AM
> To: [email protected]
> 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]]
>
> ______________________________________________
> [email protected] 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.
______________________________________________
[email protected] 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.