[R] if else lop

2011-07-05 Thread gary engstrom
I am trying to use if...else loop and have included a code snippet which I

  might like to expand.
  Maybe you could steer me in the right direction.
  library(stats)
  library(prob)
  {
   a - sample ( 1:4,100, replace=T,prob=c(0.1,0.2,0.5,0.3))
  b-sample(3:6,100,replace=T,prob=c(0.2,0.2,0.2,0.4))
  }
  dd - data.frame(a,b)
  if (subset finds a vector) ( print that vector)
  (else continue looking at subsets)
  subset(dd,isin(dd,c(1,4), ordered = FALSE))
  subset(dd,isin(dd,c(3,3),ordered=F))
  Thank you
  G

__
R-help@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.


Re: [R] if else lop

2011-07-05 Thread Sarah Goslee
Gary,

Was the second half of my message this morning not clear enough?

It wasn't clear from your original message that you were using isin()
from the prob package, rather than using isin() as pseudocode, so I'd
written a function to do that part. But the second half of my message
went through the if() part of your question. If it doesn't do what you
want, you need to be clearer about what you need that it doesn't do.

Sarah

On Tue, Jul 5, 2011 at 4:27 PM, gary engstrom engstrom.g...@gmail.com wrote:
 I am trying to use if...else loop and have included a code snippet which I

  might like to expand.
  Maybe you could steer me in the right direction.
  library(stats)
  library(prob)
  {
   a - sample ( 1:4,100, replace=T,prob=c(0.1,0.2,0.5,0.3))
  b-sample(3:6,100,replace=T,prob=c(0.2,0.2,0.2,0.4))
  }
  dd - data.frame(a,b)
  if (subset finds a vector) ( print that vector)
  (else continue looking at subsets)
  subset(dd,isin(dd,c(1,4), ordered = FALSE))
  subset(dd,isin(dd,c(3,3),ordered=F))
  Thank you
  G



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


Re: [R] if else lop

2011-07-05 Thread peter dalgaard

On Jul 5, 2011, at 22:27 , gary engstrom wrote:

 I am trying to use if...else loop

Argh! hurting of eyes and gnashing of teeth

A loop goes _around_ and around. for, repeat, while.

if ... else  is a _branching_ construct. 

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.


Re: [R] if else lop

2011-07-05 Thread Joshua Wiley
On Tue, Jul 5, 2011 at 2:53 PM, peter dalgaard pda...@gmail.com wrote:

 On Jul 5, 2011, at 22:27 , gary engstrom wrote:

 I am trying to use if...else loop

 Argh! hurting of eyes and gnashing of teeth

 A loop goes _around_ and around. for, repeat, while.

 if ... else  is a _branching_ construct.

Nominated for a fortune.


 --
 Peter Dalgaard
 Center for Statistics, Copenhagen Business School
 Solbjerg Plads 3, 2000 Frederiksberg, Denmark
 Phone: (+45)38153501
 Email: pd@cbs.dk  Priv: pda...@gmail.com

 __
 R-help@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.

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@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.


Re: [R] if else lop

2011-07-05 Thread Bert Gunter
Hi Peter:

Beware that gnashing of teeth business. My Dad, a dentist, said that
a couple of his patients who were musicians did this when they played
and ground their teeth down so much he had to make them dentures!

;-)

Cheers,
Bert

On Tue, Jul 5, 2011 at 2:53 PM, peter dalgaard pda...@gmail.com wrote:

 On Jul 5, 2011, at 22:27 , gary engstrom wrote:

 I am trying to use if...else loop

 Argh! hurting of eyes and gnashing of teeth

 A loop goes _around_ and around. for, repeat, while.

 if ... else  is a _branching_ construct.

 --
 Peter Dalgaard
 Center for Statistics, Copenhagen Business School
 Solbjerg Plads 3, 2000 Frederiksberg, Denmark
 Phone: (+45)38153501
 Email: pd@cbs.dk  Priv: pda...@gmail.com

 __
 R-help@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.




-- 
Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions.

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@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.