Re: [R] help with for loop to test for a condition in a vector

2012-11-10 Thread David Winsemius
On Nov 10, 2012, at 2:07 PM, scoyoc wrote: > I want my for loop to test for the presence of a term in a vector and return > a value to a new vector. I'm not writing it correctly though. Here's what I > have... > >> testfor = letters[1:5] >> x = c("a", "b", "e", "f", "g") >> result = rep(NA, leng

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-11-01 Thread Meredith, Christy S -FS
34 2946 2010 2.251 -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Tuesday, October 30, 2012 1:57 PM To: Meredith, Christy S -FS Cc: R help; William Dunlap Subject: Re: [R] help with for loop: new column giving count of observation for each SITEID HI, You c

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-10-30 Thread Bert Gunter
Message - > From: William Dunlap > To: "Meredith, Christy S -FS" > Cc: "r-help@r-project.org" > Sent: Tuesday, October 30, 2012 3:43 PM > Subject: Re: [R] help with for loop: new column giving count of observation > for each SITEID > > Your data w

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-10-30 Thread arun
; Cc: "r-help@r-project.org" Sent: Tuesday, October 30, 2012 3:43 PM Subject: Re: [R] help with for loop: new column giving count of observation for each SITEID Your data was, in R-readable format (from dput())   d <- data.frame(       RchID = 1:9,       site = factor(c(&qu

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-10-30 Thread Bert Gunter
20021 > 8 C 20032 > 9 C 20043 > > > Thanks so much for you help! > > -Original Message- > From: William Dunlap [mailto:wdun...@tibco.com] > Sent: Tuesday, October 30, 2012 1:07 PM > To: Meredith, Christy S -FS; r-help@R-proje

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-10-30 Thread William Dunlap
Software wdunlap tibco.com > -----Original Message----- > From: Meredith, Christy S -FS [mailto:csmered...@fs.fed.us] > Sent: Tuesday, October 30, 2012 12:20 PM > To: William Dunlap > Subject: RE: [R] help with for loop: new column giving count of observation > for each >

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-10-30 Thread Meredith, Christy S -FS
, Christy S -FS; r-help@R-project.org Subject: RE: [R] help with for loop: new column giving count of observation for each SITEID Is this what you want? > withinGroupIndex <- function(group, ...) ave(integer(length(group)), group, ..., FUN=seq_along) > site <- c("A",

Re: [R] help with for loop: new column giving count of observation for each SITEID

2012-10-30 Thread William Dunlap
Is this what you want? > withinGroupIndex <- function(group, ...) ave(integer(length(group)), group, ..., FUN=seq_along) > site <- c("A","A","C","D","C","A","B") > data.frame(site, index=withinGroupIndex(site)) site index 1A 1 2A 2 3C 1 4D 1 5

Re: [R] help with for loop

2010-01-02 Thread Bert Gunter
elp-boun...@r-project.org] On Behalf Of jim holtman Sent: Friday, January 01, 2010 5:25 PM To: Rafael Moral Cc: r-help Subject: Re: [R] help with for loop Look at your function; it is returning exactly what you are asking for: x.dif <- c(diff(my.vec), diff(my.vec, lag=i)) # the first and last values Y

Re: [R] help with for loop

2010-01-01 Thread Gabor Grothendieck
diff.zoo in the zoo package can take a vector of lags: library(zoo) z <- zoo(seq(10)^2) diff(z, 1:4) There are three vignettes (pdf documents) that come with zoo that have more info on the package. On Fri, Jan 1, 2010 at 8:16 PM, Rafael Moral wrote: > Dear useRs, > > I want to write a function

Re: [R] help with for loop

2010-01-01 Thread jim holtman
Look at your function; it is returning exactly what you are asking for: x.dif <- c(diff(my.vec), diff(my.vec, lag=i)) # the first and last values You probably want something like this: dif <- function(my.vec) { x.diff <- diff(my.vec) for(i in 2:(length(my.vec)-1)) { x.dif <- c(x.diff, diff(my.v

Re: [R] Help with for loop

2009-09-14 Thread David Winsemius
On Sep 14, 2009, at 5:14 PM, wrote: thank you all for your help. I do know how to use which() but my problem is that I am writing a function in which this is just part of it. After seeing the (a-b)[bfor which is negative and which is positive. Can you explain what you mean? There are

Re: [R] Help with for loop

2009-09-14 Thread Jorge Ivan Velez
e...@msn.com > Cell Phone: 510-371-4717 > > > > > -- > From: www...@gmail.com > Date: Mon, 14 Sep 2009 16:35:23 -0300 > Subject: Re: [R] Help with for loop > To: dwinsem...@comcast.net > CC: jorgeivanve...@gmail.com; r-help@r-project.org; edche...@gmail.com > > > Or:

Re: [R] Help with for loop

2009-09-14 Thread edchen51
thank you all for your help. I do know how to use which() but my problem is that I am writing a function in which this is just part of it. After seeing the (a-b)[b wrote: On Sep 14, 2009, at 3:02 PM, Jorge Ivan Velez wrote: Hi Edward, Here is a suggestion: a = c(4,5,1,7,8,12,39) b =

Re: [R] Help with for loop

2009-09-14 Thread Henrique Dallazuanna
Or: (a - b)[b < a] On Mon, Sep 14, 2009 at 4:16 PM, David Winsemius wrote: > > On Sep 14, 2009, at 3:02 PM, Jorge Ivan Velez wrote: > > Hi Edward, >> Here is a suggestion: >> >> a = c(4,5,1,7,8,12,39) >> b = c(3,7,8,4,7,25,78) >> d <- a-b >> d[which(d>0)] >> # [1] 1 3 1 >> > > #Or even: > d <-

Re: [R] Help with for loop

2009-09-14 Thread David Winsemius
On Sep 14, 2009, at 3:02 PM, Jorge Ivan Velez wrote: Hi Edward, Here is a suggestion: a = c(4,5,1,7,8,12,39) b = c(3,7,8,4,7,25,78) d <- a-b d[which(d>0)] # [1] 1 3 1 #Or even: d <- (a-b)[which((a-b)>0)] d #[1] 1 3 1 HTH, Jorge On Mon, Sep 14, 2009 at 2:50 PM, Edward Chen wrote:

Re: [R] Help with for loop

2009-09-14 Thread Jorge Ivan Velez
Hi Edward, Here is a suggestion: a = c(4,5,1,7,8,12,39) b = c(3,7,8,4,7,25,78) d <- a-b d[which(d>0)] # [1] 1 3 1 HTH, Jorge On Mon, Sep 14, 2009 at 2:50 PM, Edward Chen wrote: > I have a code: > *a = c(4,5,1,7,8,12,39) > b = c(3,7,8,4,7,25,78) > d =a-b > for(i in 1:length(d)){ > if(d[i]>0){x

Re: [R] Help with for loop

2009-09-14 Thread Erik Iverson
It is difficult to know what you're trying to do here, I think. Is this it? You almost surely don't need a for loop to accomplish your task, and should make use of the pre-existing vectorized functions provided to you. a <- c(4, 5, 1, 7, 8, 12, 39) b <- c(3, 7, 8, 4, 7, 25, 78) d <- a - b whi

Re: [R] help with for loop

2009-09-11 Thread Steve Lianoglou
Hi, On Sep 11, 2009, at 6:35 PM, Edward Chen wrote: example code: P = function(whichday,columns){ y = which(pvalue[,whichday]0){ #diffbig = meandayxx0) x[i] = raw_urine[x_index[i],1] dayx[i]= raw_urine[x_index[i],day1_ind] dayy[i] = raw_urine[x_index[i],columns] jpeg("test 1.jpg",width=800, hei