I have a vector that has 1,974 elements and each element is one of the following (B, F, N, Y). How do I recreate that vector accept in the place of N put 0 and in the place of B, F or Y put a 1? Thanks, Jacob [[alternative HTML version deleted]]
I think you want ifelse(x=='N',0,1)> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Davis, > Jacob B. > Sent: Friday, June 16, 2006 4:46 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Vector Manipulation > > I have a vector that has 1,974 elements and each element is > one of the following (B, F, N, Y). How do I recreate that > vector accept in the place of N put 0 and in the place of B, > F or Y put a 1? > > > > Thanks, > > Jacob > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
try the following: x <- c("B", "F", "N", "Y") ################ y <- numeric(length(x)) y[x != "N"] <- 1 y I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting "Davis, Jacob B. " <JBDavis at txfb-ins.com>:> I have a vector that has 1,974 elements and each element is one of > the > following (B, F, N, Y). How do I recreate that vector accept in the > place of N put 0 and in the place of B, F or Y put a 1? > > > > Thanks, > > Jacob > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Hi or slightly quicker y<-(x != "N")*1 HTH Petr On 16 Jun 2006 at 22:57, Dimitrios Rizopoulos wrote: Date sent: Fri, 16 Jun 2006 22:57:48 +0200 From: Dimitrios Rizopoulos <Dimitris.Rizopoulos at med.kuleuven.be> To: "Davis, Jacob B. " <JBDavis at txfb-ins.com> Copies to: r-help at stat.math.ethz.ch Subject: Re: [R] Vector Manipulation> try the following: > > x <- c("B", "F", "N", "Y") > ################ > y <- numeric(length(x)) > y[x != "N"] <- 1 > y > > > I hope it helps. > > Best, > Dimitris > > ---- > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > Quoting "Davis, Jacob B. " <JBDavis at txfb-ins.com>: > > > I have a vector that has 1,974 elements and each element is one of > > the following (B, F, N, Y). How do I recreate that vector accept in > > the place of N put 0 and in the place of B, F or Y put a 1? > > > > > > > > Thanks, > > > > Jacob > > > > > > > > > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz