[tech-spec] Re: R functions

  • From: "Steve Wisdom" <swis@xxxxxxxxxxxx>
  • To: <tech-spec@xxxxxxxxxxxxx>
  • Date: Tue, 14 Dec 2004 10:23:35 -0500

__
James Sogi [mailto:jsogi@xxxxxxxxxxxxx] :

> Thanks to the Boilermaker's helpful hint, made some progress in R.
> Any suggestions to improve crudeness?

Kudos to Jim for pushing the football down the field.  One suggestion -

# random numbers; i don't have jim's data in hand
r1<-
round(100*data.frame(d=rnorm(50),d1=rnorm(50),d2=rnorm(50),d3=rnorm(50)));
r1
# jim's code
nr<-subset(r1,d<0 & d1<0 & d2 < 0 , select = d3); nr
# first thought, accomodate arbitrary number of columns <0
nr<-subset(r1,apply(r1[,1:3]<0,1,all), select = d3); nr
# second thought, why bother with subset
nr<- r1[apply(r1[,1:3]<0,1,all),4,drop=F]; nr
# probably dirk could think up a more elegant solution







Other related posts: