An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130226/495f44f2/attachment.pl>
Merging value labels into indicator variable.
5 messages · Tasnuva Tabassum, Pete Brecknock, Berend Hasselman +1 more
tasnuvat wrote
I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9. I want to make an indicator variable that will take value 1 if NAM=7 or NAM=8 or NAM=9. How can I do that? I usually do: Var001<- ifelse(NAM==7,1,0) for the simplest case. [[alternative HTML version deleted]]
______________________________________________
R-help@
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.
How about something like ... NAM = c(1,2,3,4,5,6,7,8,9) ifelse(NAM>=7,1,0) # or ifelse(NAM %in% c(7,8,9),1,0) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Merging-value-labels-into-indicator-variable-tp4659703p4659705.html Sent from the R help mailing list archive at Nabble.com.
On 26-02-2013, at 18:45, Tasnuva Tabassum <t.tasnuva at gmail.com> wrote:
I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9. I want to make an indicator variable that will take value 1 if NAM=7 or NAM=8 or NAM=9. How can I do that? I usually do: Var001<- ifelse(NAM==7,1,0) for the simplest case.
How about Var001<- ifelse(NAM>=7 & NAM<=9,1,0) Berend
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130227/da61b57f/attachment.pl>
Hi can not resist Var001 <- (NAM>=7 & NAM<=9)*1 Regards Petr
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Tasnuva Tabassum Sent: Tuesday, February 26, 2013 7:03 PM To: Berend Hasselman Cc: R help Subject: Re: [R] Merging value labels into indicator variable. Thanx all, I found my answer. I prefer Peter's second solution. On Tue, Feb 26, 2013 at 11:59 PM, Berend Hasselman <bhh at xs4all.nl> wrote:
On 26-02-2013, at 18:45, Tasnuva Tabassum <t.tasnuva at gmail.com>
wrote:
I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9. I
want
to make an indicator variable that will take value 1 if NAM=7 or NAM=8 or NAM=9. How can I do that? I usually do: Var001<- ifelse(NAM==7,1,0) for the simplest case.
How about Var001<- ifelse(NAM>=7 & NAM<=9,1,0) Berend
[[alternative HTML version deleted]]
______________________________________________ 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.