joe1985
2009-Jan-29 09:25 UTC
[R] Text in a character vector to indicate "ifelse" argument
Hello I have a data set that looks like this;> b2dato chr status PRRSvac PRRSsanVac PRRSsanDk PRRSdk 33 2007-12-03 090432 R?d SPF 34 2007-02-09 090432 R?d SPF+sanDK 35 2002-12-17 090432 R?d SPF+DK 36 2002-11-27 090432 R?d SPF+sanDK 37 2002-07-23 090432 R?d SPF+DK 38 2001-08-23 090432 R?d SPF 39 2000-01-01 090432 SPF-X, PRRS-neg. 40 1999-05-01 090432 MS-X, PRRS-neg. 81 2001-08-23 022458 R?d SPF 82 1999-01-22 022458 SPF-X, PRRS-neg. 130 2008-10-16 080385 R?d SPF+Myc+Ap2+Nys+DK+Vac 131 2003-03-18 080385 R?d SPF+Myc+Ap2+DK+Vac 132 2002-11-01 080385 R?d SPF+Myc+DK+Vac 133 2002-02-07 080385 R?d SPF+Myc+Vac 134 2000-09-19 080385 MS-X, PRRS-pos VAC 135 1999-01-22 080385 MS-X, PRRS-neg 176 2008-10-28 013168 R?d SPF+Myc+Ap2+Nys+DK+Vac 177 2003-05-23 013168 R?d SPF+Myc+Ap2+DK+Vac 178 2002-11-01 013168 R?d SPF+Myc+DK+Vac 179 2001-07-03 013168 R?d SPF+Myc+Vac 180 2000-09-01 013168 MS-X, PRRS-pos VAC 181 2000-06-02 013168 MS-X, PRRS-neg 182 2000-04-03 013168 SKM-X, +Ap2, PRRS-neg 183 1999-01-22 013168 MS-X, PRRS-neg Where I have used; b2$PRRSvac <- ifelse(b2$status=='PRRS-pos VAC' | b2$status=='Vac',1,0) b2$PRRSdk <- ifelse(b2$status=='PRRS-pos DK' | b2$status=='DK',1,0) b2$PRRSsanVac <- ifelse(b2$status=='sanVac',1,0) b2$PRRSsanDk <- ifelse(b2$status=='sanDK',1,0) to creat the last four variables, but it wont work!!! The variable status has class "character". Can anyone help me? -- View this message in context: http://www.nabble.com/Text-in-a-character-vector-to-indicate-%22ifelse%22-argument-tp21722983p21722983.html Sent from the R help mailing list archive at Nabble.com.
Petr PIKAL
2009-Jan-29 10:09 UTC
[R] Odp: Text in a character vector to indicate "ifelse" argument
Hi r-help-bounces at r-project.org napsal dne 29.01.2009 10:25:13:> > Hello > > I have a data set that looks like this; > > > b2 > dato chr status PRRSvac > PRRSsanVac PRRSsanDk PRRSdk > 33 2007-12-03 090432 R?d SPF > 34 2007-02-09 090432 R?d SPF+sanDK > 35 2002-12-17 090432 R?d SPF+DK > 36 2002-11-27 090432 R?d SPF+sanDK > 37 2002-07-23 090432 R?d SPF+DK > 38 2001-08-23 090432 R?d SPF > 39 2000-01-01 090432 SPF-X, PRRS-neg. > 40 1999-05-01 090432 MS-X, PRRS-neg. > 81 2001-08-23 022458 R?d SPF > 82 1999-01-22 022458 SPF-X, PRRS-neg. > 130 2008-10-16 080385 R?d SPF+Myc+Ap2+Nys+DK+Vac > 131 2003-03-18 080385 R?d SPF+Myc+Ap2+DK+Vac > 132 2002-11-01 080385 R?d SPF+Myc+DK+Vac > 133 2002-02-07 080385 R?d SPF+Myc+Vac > 134 2000-09-19 080385 MS-X, PRRS-pos VAC > 135 1999-01-22 080385 MS-X, PRRS-neg > 176 2008-10-28 013168 R?d SPF+Myc+Ap2+Nys+DK+Vac > 177 2003-05-23 013168 R?d SPF+Myc+Ap2+DK+Vac > 178 2002-11-01 013168 R?d SPF+Myc+DK+Vac > 179 2001-07-03 013168 R?d SPF+Myc+Vac > 180 2000-09-01 013168 MS-X, PRRS-pos VAC > 181 2000-06-02 013168 MS-X, PRRS-neg > 182 2000-04-03 013168 SKM-X, +Ap2, PRRS-neg > 183 1999-01-22 013168 MS-X, PRRS-neg > > Where I have used; > > b2$PRRSvac <- ifelse(b2$status=='PRRS-pos VAC' | b2$status=='Vac',1,0) > b2$PRRSdk <- ifelse(b2$status=='PRRS-pos DK' | b2$status=='DK',1,0) > b2$PRRSsanVac <- ifelse(b2$status=='sanVac',1,0) > b2$PRRSsanDk <- ifelse(b2$status=='sanDK',1,0) > > to creat the last four variables, but it wont work!!! The variablestatus> has class "character".What "wont work!!!" means> zdrzenisklon ot doba typ spolf spol.f 1 35 3.00 70.00 stand 35.stand 35.stand 2 50 20.00 9.50 stand 50.stand 50.stand 3 50 5.00 29.50 stand 50.stand 50.stand 4 50 15.00 13.00 stand 50.stand 50.stand ....> zdrzeni$v1<-ifelse(zdrzeni$typ=="stand"|zdrzeni$typ=="not", 1,0) > zdrzenisklon ot doba typ spolf spol.f v1 1 35 3.00 70.00 stand 35.stand 35.stand 1 2 50 20.00 9.50 stand 50.stand 50.stand 1 3 50 5.00 29.50 stand 50.stand 50.stand 1 4 50 15.00 13.00 stand 50.stand 50.stand 1 .... obviously "works", so the problem is in your data and your use of "==". ifelse(x=="abc", 1,0) means that the result is 1 if x is exactly equivalent to "abc" and 0 if x is " abc", "def-abc" or in any other variation. You probably need to use grep and regexpr expression for test but it is not my cup of tea. Regards Petr> > Can anyone help me? > > -- > View this message in context: http://www.nabble.com/Text-in-a-character- > vector-to-indicate-%22ifelse%22-argument-tp21722983p21722983.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Hi, I know that some graphics devices in R store graphics primitives such that a redraw is possible (e.g. when resizing the window). Is it possible to get the current number of stored graphic primitives? Thanks in advance Sigbert Klinke
Sigbert Klinke wrote:> Hi, > > I know that some graphics devices in R store graphics primitives such > that a redraw is possible (e.g. when resizing the window). Is it > possible to get the current number of stored graphic primitives? > > Thanks in advance > > Sigbert Klinke > > ______________________________________________ > 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. >You could examine the results of recordPlot, but note the warnings that the format is not guaranteed to be stable across R versions. Duncan Murdoch
Sigbert, The plot2script function in the TeachingDemos package does essentially what Duncan talks about for you. Create your plot then run the function giving it a filename to save the info into (or run without arguments and then past into a script window or text editor (only tested on windows, if this does not work, go with the filename option)). The same warnings (and possibly more) apply, but this lets you see the steps to recreate the plot (and you can try modifying some parts and running the script as a way to update the plot). One thing this tends to show is the number and type of steps that the plotting process gets broken down into. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Duncan Murdoch > Sent: Thursday, January 29, 2009 4:25 AM > To: Sigbert Klinke > Cc: r-help at r-project.org > Subject: Re: [R] Graphic device & graphics primitives > > Sigbert Klinke wrote: > > Hi, > > > > I know that some graphics devices in R store graphics primitives such > > that a redraw is possible (e.g. when resizing the window). Is it > > possible to get the current number of stored graphic primitives? > > > > Thanks in advance > > > > Sigbert Klinke > > > > ______________________________________________ > > 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. > > > You could examine the results of recordPlot, but note the warnings that > the format is not guaranteed to be stable across R versions. > > Duncan Murdoch > > ______________________________________________ > 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.
Possibly Parallel Threads
- extracting parts of words or extraxting letter to use in ifelse-func.
- Getting data from a PDF-file into R
- t.test in a loop
- Odp: Odp: extracting parts of words or extraxting letter to use in ifelse-func.
- Segfault on ".C" registration via R_CMethodDef according to 'Writing R Extensions'.