Re: [R] apply question

2013-10-27 Thread Andras Farkas
not homework, but thanks for the hint! Andras On Sunday, October 27, 2013 7:51 AM, Patrick Burns wrote: Homework?  A hint is: ?diff Pat On 27/10/2013 11:37, Andras Farkas wrote: > Dear All, > > please help with the following problem: > > I have > > > t <-seq(0,24,by=6) > a <-600 > g <-0

Re: [R] apply question

2013-10-27 Thread Patrick Burns
Homework? A hint is: ?diff Pat On 27/10/2013 11:37, Andras Farkas wrote: Dear All, please help with the following problem: I have t <-seq(0,24,by=6) a <-600 g <-0.05 b <-a*exp(-g*t) I would like to establish a vector called z (for example) based on b where the results are calculated as

[R] apply question

2013-10-27 Thread Andras Farkas
Dear All, please help with the following problem: I have t <-seq(0,24,by=6) a <-600 g <-0.05 b <-a*exp(-g*t)    I would like to establish a vector called z (for example) based on b where the results are calculated as : z <-c(a-b[1],b[1]-b[2],b[2]-b[3],b[3]-b[4],b[4]-b[5]) so the results are:

Re: [R] apply question

2012-08-21 Thread Bert Gunter
... or using the handy with() with(x,paste(n,l,sep="_")) Slightly greater clarity and robustness, perhaps... -- Bert On Tue, Aug 21, 2012 at 9:24 AM, R. Michael Weylandt wrote: > You don't need loops or apply with paste since it's vectorized: > > x <- data.frame(n = 1:5, l = letters[1:5], stri

Re: [R] apply question

2012-08-21 Thread R. Michael Weylandt
You don't need loops or apply with paste since it's vectorized: x <- data.frame(n = 1:5, l = letters[1:5], stringsAsFactors = FALSE) paste(x[,1], x[,2], sep = "_") Cheers, Michael On Tue, Aug 21, 2012 at 10:57 AM, Chet Seligman wrote: > This works, where zz is a dataframe: > > for(i in 1:nrow(

Re: [R] apply question

2012-08-21 Thread Jeff Newmiller
What is wrong with utilizing the vectorized nature of paste? zz[[1]] <- paste(zz[[1]],zz[[2]],sep="_") --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Liv

[R] apply question

2012-08-21 Thread Chet Seligman
This works, where zz is a dataframe: for(i in 1:nrow(zz)) { zzz[i,1]<-paste(zz[i,1],zz[i,2],sep="_") } I would like to use "apply" to concatentate two columns of text along with a separator. How? Chet [[alternative HTML version deleted]] __

Re: [R] apply question

2011-09-17 Thread Jorge I Velez
Hi clsnyder, You forgot the MARGIN argument in you function call. Take a look at ?apply apply(iris, 2, length) apply(iris, 2, mean) HTH, Jorge * * On Sat, Sep 17, 2011 at 6:42 PM, clsnyder <> wrote: > Why does one method work, and the other not? > > attach(iris) > head(iris) > > mean(Sepal.L

[R] apply question

2011-09-17 Thread clsnyder
Why does one method work, and the other not? attach(iris) head(iris) mean(Sepal.Length) [1] 5.84 apply(iris, Sepal.Length, mean) "Error in if (d2 == 0L) { : missing value where TRUE/FALSE needed" I seem to get this error frequently with the apply functions but other "manual" methods work no

Re: [R] apply question

2010-05-03 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 30.04.2010 23:11:54: > Hello David, > > On Apr 30, 2010, at 11:00 PM, David Winsemius wrote: > > Note: Loops may be just as fast or faster than apply calls. > > > How come!? is this true also for other similar functions: lapply, tapply and sapply? >

Re: [R] apply question

2010-04-30 Thread Giovanni Azua
Hello David, On Apr 30, 2010, at 11:00 PM, David Winsemius wrote: > Note: Loops may be just as fast or faster than apply calls. > How come!? is this true also for other similar functions: lapply, tapply and sapply? Then the only advantage of these above is only syntactic sugar? >> >> indices

Re: [R] apply question

2010-04-30 Thread David Winsemius
On Apr 30, 2010, at 4:52 PM, Giovanni Azua wrote: Hello, I have a bootstrap implementation loop that I would like to replace by a faster "batch operator". The loop is as follows: for (b in 1:B) { indices <- sample(1:N, size=N, replace=TRUE) # sample n elements with replacement theta_s

[R] apply question

2010-04-30 Thread Giovanni Azua
Hello, I have a bootstrap implementation loop that I would like to replace by a faster "batch operator". The loop is as follows: for (b in 1:B) { indices <- sample(1:N, size=N, replace=TRUE) # sample n elements with replacement theta_star[b,] = statistic(data,indices) # exe