Skip to content

Text in a character vector to indicate "ifelse" argument

6 messages · joe1985, PIKAL Petr, Sigbert Klinke +3 more

#
Hello

I have a data set that looks like this;
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 variable status
has class "character". 

Can anyone help me?
#
Hi

r-help-bounces at r-project.org napsal dne 29.01.2009 10:25:13:
status
What "wont work!!!" means
sklon    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
....
sklon    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
http://www.R-project.org/posting-guide.html
#
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
#
On Thu, 29 Jan 2009, Sigbert Klinke wrote:

            
That's not what happens: the graphics engine stores a display list for 
the current device (if enabled), this being a set of graphics calls. 
Devices repaint from either backing store or asking the engine to 
replay the display list.

See ?dev.control. There is no public API to the display list, but of 
course you can interrogate it by C code, with the usual risks.
This looks very like a programming question for R-devel: it *is* about 
R's internals.
#
Sigbert Klinke wrote:
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,