Re: [R] when to use which apply function?

2013-03-27 Thread C W
Thanks for pointing that out. Mike On Tue, Mar 26, 2013 at 6:53 PM, David Winsemius wrote: > > On Mar 26, 2013, at 2:51 PM, C W wrote: > > > Dear list, > > > > I am a little confused as to when to use apply, sapply, tapply, vapply, > > replicate. I've encountered this several times, > > This is

Re: [R] when to use which apply function?

2013-03-26 Thread David Winsemius
On Mar 26, 2013, at 2:51 PM, C W wrote: > Dear list, > > I am a little confused as to when to use apply, sapply, tapply, vapply, > replicate. I've encountered this several times, > This is time, this is what I am working on, > > mat <- matrix(c(seq(from=1, to=10), rnorm(10)), ncol=2) > > a=1;

Re: [R] when to use which apply function?

2013-03-26 Thread Rui Barradas
Hello, The correct syntax would be sapply(1:10, function(i) newfun(x=mat[i, 1], y=mat[i, 2], a=a, b=b)) Hope this helps, Rui Barradas Em 26-03-2013 21:51, C W escreveu: Dear list, I am a little confused as to when to use apply, sapply, tapply, vapply, replicate. I've encountered this sev

[R] when to use which apply function?

2013-03-26 Thread C W
Dear list, I am a little confused as to when to use apply, sapply, tapply, vapply, replicate. I've encountered this several times, This is time, this is what I am working on, mat <- matrix(c(seq(from=1, to=10), rnorm(10)), ncol=2) a=1; b=5 newfun <- function(x, y, a, b) { x*y+a+b } sap

Re: [R] when to use `which'?

2011-07-13 Thread William Dunlap
unlap TIBCO Spotfire From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of csrabak [cra...@acm.org] Sent: Wednesday, July 13, 2011 6:20 AM To: r-h...@stat.math.ethz.ch Subject: Re: [R] when to use `which'? Em 12/7/2011 17:29, David Winsemius escreveu: > [snipped

Re: [R] when to use `which'?

2011-07-13 Thread csrabak
Em 12/7/2011 17:29, David Winsemius escreveu: [snipped] If you have millions of records and tens of thousands of NA's (say ~ 1% of the data), imagine what your console looks like if you try to pick out records from one day and get 10,000 where you were expecting 100. A real PITA when you are

Re: [R] when to use `which'?

2011-07-12 Thread Joshua Wiley
On Tue, Jul 12, 2011 at 1:17 PM, Sam Steingold wrote: > when do I need to use which()? See ?which For examples, try: example(which) >> a <- c(1,2,3,4,5,6) >> a > [1] 1 2 3 4 5 6 >> a[a==4] > [1] 4 >> a[which(a==4)] > [1] 4 >> which(a==4) > [1] 4 >> a[which(a>2)] > [1] 3 4 5 6 >> a[a>2] > [1] 3

Re: [R] when to use `which'?

2011-07-12 Thread David Winsemius
On Jul 12, 2011, at 4:17 PM, Sam Steingold wrote: when do I need to use which()? a <- c(1,2,3,4,5,6) a [1] 1 2 3 4 5 6 a[a==4] [1] 4 a[which(a==4)] [1] 4 which(a==4) [1] 4 a[which(a>2)] [1] 3 4 5 6 a[a>2] [1] 3 4 5 6 seems unnecessary... It is unnecessary when `a` is a toy ca

Re: [R] when to use `which'?

2011-07-12 Thread Bert Gunter
Well ... which(a==4)^2 ?? -- Bert On Tue, Jul 12, 2011 at 1:17 PM, Sam Steingold wrote: > when do I need to use which()? >> a <- c(1,2,3,4,5,6) >> a > [1] 1 2 3 4 5 6 >> a[a==4] > [1] 4 >> a[which(a==4)] > [1] 4 >> which(a==4) > [1] 4 >> a[which(a>2)] > [1] 3 4 5 6 >> a[a>2] > [1] 3 4 5 6 >> >

[R] when to use `which'?

2011-07-12 Thread Sam Steingold
when do I need to use which()? > a <- c(1,2,3,4,5,6) > a [1] 1 2 3 4 5 6 > a[a==4] [1] 4 > a[which(a==4)] [1] 4 > which(a==4) [1] 4 > a[which(a>2)] [1] 3 4 5 6 > a[a>2] [1] 3 4 5 6 > seems unnecessary... -- Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031 htt