[R] Scripting - query

Dan Davison davison at stats.ox.ac.uk
Sun Aug 10 12:39:57 CEST 2008


On Sun, Aug 10, 2008 at 02:44:00PM +1200, Gareth Campbell wrote:
> I have a vector:
> alleles.present<-c("D3", "D16", ... )
> 
> The alleles present changes given the case I'm dealing with - i.e. either
> all of the alleles I use for my calculations are present, or some of them.
> 
> Depending on what alleles are present, I need to make matrices and do
> calculations on those alleles present and completely disregard any formula
> or other use of the alleles not present.
> 
> I'm trying to figure out the best way to do this.
> 
> Basically I'm trying to do if() commands (with no success so far) to allow
> me to query the alleles.present for the presence of each allele I use and
> then let dictate which formula to use etc...
> 
> Does anyone have a good way to do this?  I've been fiddling with grep()
> etc... but I can't get it to do what I need!!  Very frustrating.

It's going to be hard for people to make good suggestions here without
a concrete example. Can you provide a toy example that is as simple as
possible, while illustrating (some of) the problems you are trying to
solve?

Dan

p.s. Are you familiar with %in% ? E.g.

if("D3" %in% alleles.present) do.something()
else do.something.else()

See help("%in%")


> 
> Thanks very much
> 
> -- 
> Gareth Campbell
> PhD Candidate
> The University of Auckland
> 
> P +649 815 3670
> M +6421 256 3511
> E gareth.campbell at esr.cri.nz
> gcam032 at gmail.com
> 
> 	[[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.



More information about the R-help mailing list