[R] 'which' statement for recode?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Jan 22 17:08:11 CET 2015


?factor

You might find the description in the Introduction to R that comes with the R software helpful if the help page seems terse.

Please read the Posting Guide and particular post using plain text format, a strong in your email program.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On January 22, 2015 8:01:25 AM PST, Charles Stangor <cstangor at gmail.com> wrote:
>Hi,
>
>Is there a way to easily convert the list of course terms into
>sequential
>integers in the dataframe (see code below)?
>
>eg. "199801" = 1; "199808"=2
>
>I know I can use recode but shouldn't "which" work?
>
>Thanks in advance!
>
>
>sc = data.frame(c("200208", "200701", "201201"))
>names(sc) = c("TERM")
>
>TermList = c(NA, "199801", "199808", "199901", "199908", "200001",
>"200008", "200101", "200108",
>            "200201", "200208", "200301", "200308", "200401", "200408",
>"200501", "200508",
>            "200601", "200608", "200701", "200708", "200801", "200808",
>"200901", "200908",
>            "201001", "201008", "201101", "201108", "201201", "201308",
>"201401", "201408")
>
>which(TermList==sc$TERM)
>
>	[[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