Re: [R] Help with loop for column means into new column by a subset Factor w/131 levels

2019-04-30 Thread Bill Poling
I ran this routine but I was thinking there must be a more elegant way of doing this. #https://community.rstudio.com/t/how-to-average-mean-variables-in-r-based-on-the-level-of-another-variable-and-save-this-as-a-new-variable/8764/8 hcd2tmp2_summmary <- hcd2tmp2 %>% select(.) %>% group_by(Pr

[R] Help with loop for column means into new column by a subset Factor w/131 levels

2019-04-30 Thread Bill Poling
Good afternoon. #RStudio Version 1.1.456 sessionInfo() #R version 3.5.3 (2019-03-11) #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows >= 8 x64 (build 9200) #I have a DF of 8 columns and 14025 rows str(hcd2tmp2) # 'data.frame':14025 obs. of 8 variables: # $ Submitted_Charge:

Re: [R] Help with loop ;(

2013-10-22 Thread arun
Hi, The conditions are not very clear. For example, it is not mentioned whether vectors are of same length or not.  Assuming the former case: fun1 <- function(x,y){  if(length(x)==length(y) & length(x)%%2==0){  res <- x+y  }  else if(length(x)==length(y) & length(x)%%2==1){  res <- abs(x-y) } el

Re: [R] Help with loop

2012-11-22 Thread arun
- From: Hefri To: r-help@r-project.org Cc: Sent: Thursday, November 22, 2012 6:43 AM Subject: Re: [R] Help with loop Hi again, I was thinking that the interval would stop when there was a NA, ignore subsequent NAs and only start a new interval when there was a new value. So in the example below, the int

Re: [R] Help with loop

2012-11-22 Thread Hefri
Hi again, I was thinking that the interval would stop when there was a NA, ignore subsequent NAs and only start a new interval when there was a new value. So in the example below, the interval would stop at row 320, and a new interval started at row 334. > head (D, 20) Salt time 319

Re: [R] Help with loop

2012-11-22 Thread Rui Barradas
Hello, I'm glad it helped. You should have kept this in the list, the odds of getting more answers are bigger. As for your problem with NAs, what do you want to do with them? Should they count as within range? Rui Barradas Em 22-11-2012 10:18, Helene Frigstad escreveu: Hi, yes, that is a v

Re: [R] Help with loop

2012-11-21 Thread Rui Barradas
Hello, If I understand it well, this might avoid a loop. dat <- read.table(text=" Salt time 1 35.65114 2003-07-19 2 35.64226 2003-07-20 3 35.62411 2003-07-21 4 35.62473 2003-07-22 5 35.65893 2003-07-23 6 35.70140 2003-07-24 7 35.62157 2003-07-25 8 35.64122 2003-07-26 9 35.63515 2

[R] Help with loop

2012-11-21 Thread Hefri
Hi, I have used R for some time, but managed to avoid writing loops. But this time I am afraid there is no way around it. I have a dataframe with time and salinity (see below). I would like to extract the time intervals where salinity changes by less than 0.05. So using the values below this wo

Re: [R] help with Loop

2012-07-23 Thread Rui Barradas
Hello, Try the following. d <- read.table(text=" D Y C a 2005 10 a 2006 0 a 2007 9 b 2005 1 b 2006 0 b 2007 1 c 2005 5 c 2006 NA c 2007 4 ", header=TRUE) d prn <- lapply(split(d, d$D), function(x){ x <- x[!is.na(x$C), ] x[c(FALSE, diff(x$C)/x$C[-length(x$C)] < -0.5 & diff(x$C) < -5), ]

[R] help with Loop

2012-07-23 Thread Katrin Ronnenberg
hello there, I'm an R beginner and got plunged into this. I guess my attempts are hopeless so far, so I won't even show them. I want to write a loop, which prints all erroneous values. My definition of erroneous: If the current counts (partridge counts in a hunting district) differ from last yea

Re: [R] Help with loop

2012-07-12 Thread arun
.0 19.0 4  4.0  8.0 12.00  1.6 20.0 #or sapply(colnames(df1),function(x) func1(x,df1,df2)) A.K. - Original Message - From: paulalou To: r-help@r-project.org Cc: Sent: Wednesday, July 11, 2012 10:11 AM Subject: [R] Help with loop Hi, I have two dataframes: The first, df1, contains som

Re: [R] Help with loop

2012-07-11 Thread Charles Stangor
I think I just learned this myself: Don't put the $ extension in the bracket : df1$cola[is.na(df1$cola)]<- > > df2$cola > Instead substitute using brackets within the brackets: df1["cola"]is.na(df1["cola"])]<- > > df2["cola"] > then the "cola" s can be substituted. > Maybe this will help

Re: [R] Help with loop

2012-07-11 Thread Rui Barradas
Hello, A one-liner could be df1 <- read.table(text=" cola colb colc cold cole 1NA59 NA 17 2NA6 NA 14 NA 3 3NA 11 15 19 4 48 12 NA 20 ", header=TRUE) df2 <- read.table(text=" cola colb colc cold cole 1 1.4 0.8 0.02 1.6 0.6 ", header=

[R] Help with loop

2012-07-11 Thread paulalou
Hi, I have two dataframes: The first, df1, contains some missing data: cola colb colc cold cole 1NA59 NA 17 2NA6 NA 14 NA 3 3NA 11 15 19 4 48 12 NA 20 The second, df2, contains the following: cola colb colc cold cole 1 1.4 0.8 0.

Re: [R] Help with Loop Please!

2009-09-13 Thread Henrique Dallazuanna
Try this: apply(subset.models[,-1], 1, function(x)lm(as.formula(paste('y ~', paste(names(freeny[,-1])[x], collapse = "+"), sep = "")), data = freeny)) On Sun, Sep 13, 2009 at 10:57 AM, Axel Urbiz wrote: > Hi, > > I’d like to fit one GLM model for each possible combination of inputs (i.

[R] Help with Loop Please!

2009-09-13 Thread Axel Urbiz
Hi, I’d like to fit one GLM model for each possible combination of inputs (i.e. exhaustive search). The package leaps can help me to generate all possible variable subsets, but I’ll appreciate your guidance as of how to generate one model for each of those possible subsets. I’m new in R! Thanks i

Re: [R] Help with Loop!

2009-07-23 Thread Steve Lianoglou
Hi, On Jul 23, 2009, at 7:30 PM, Lars Bishop wrote: Dear experts, I'm new in R and trying to learn by writing a version of the Perceptron Algorithm. How can I tell in the code below to stop the iteration when the condition in the "for loop" is not satisfied for all training examples? T

[R] Help with Loop!

2009-07-23 Thread Lars Bishop
Dear experts, I'm new in R and trying to learn by writing a version of the Perceptron Algorithm. How can I tell in the code below to stop the iteration when the condition in the "for loop" is not satisfied for all training examples? Thanks in advance for your help! ## Generate a linearly separa

Re: [R] help with loop

2009-03-12 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: > is your data a data frame or a matrix? do you want to compute the > differences columnwise, i.e., for each column independently? consider > this example: > > # generate and display dummy data > (d = as.data.frame(replicate(3, sample(5 > > # compute succe

Re: [R] help with loop

2009-03-12 Thread Rafael Moral
Thank you guys, it's a lot simpler than I thought. Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinf

Re: [R] help with loop

2009-03-12 Thread baptiste auguie
On 12 Mar 2009, at 13:22, richard.cot...@hsl.gov.uk wrote: I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. This is just sum(diff(x)), or even x[length(x)] - x[1]. I think r

Re: [R] help with loop

2009-03-12 Thread Jorge Ivan Velez
Dear Rafael, Perhaps: sum(diff(x)) where x is your vector. To apply above to your data set (by rows), you could use apply(mydata,1,function(x) sum(diff(x))) See ?diff, ?sum and ?apply for more information. HTH, Jorge On Thu, Mar 12, 2009 at 9:04 AM, Rafael Moral wrote: > Dear useRs, > I'm

Re: [R] help with loop

2009-03-12 Thread Gabor Grothendieck
This is a telescoping sum that can be calculated analytically as: (a[2] - a[1]) + ... + (a[n] - a[n-1]) = a[n] - a[1] On Thu, Mar 12, 2009 at 9:04 AM, Rafael Moral wrote: > Dear useRs, > I'm trying to write a loop to sum my data in the following way: > (the second - the first) + (the third - t

Re: [R] help with loop

2009-03-12 Thread Romain Francois
Well actually, what about that (Assuming mydata is a data frame) tail( mydata, 1 ) - head( mydata, 1) since: (the second - the first) + (the third - the second) + (the fourth - the third) = the last - the first Romain Rafael Moral wrote: Dear useRs, I'm trying to write a loop to sum my data

Re: [R] help with loop

2009-03-12 Thread Richard . Cotton
> I'm trying to write a loop to sum my data in the following way: > (the second - the first) + (the third - the second) + (the fourth - > the third) + ... > for each column. This is just sum(diff(x)), or even x[length(x)] - x[1]. Regards, Richie. Mathematical Sciences Unit HSL ---

Re: [R] help with loop

2009-03-12 Thread Romain Francois
Hi, Try this; lapply( mydata, function(x){ sum( diff( x ) ) } ) Romain Rafael Moral wrote: Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote someth

Re: [R] help with loop

2009-03-12 Thread Wacek Kusnierczyk
is your data a data frame or a matrix? do you want to compute the differences columnwise, i.e., for each column independently? consider this example: # generate and display dummy data (d = as.data.frame(replicate(3, sample(5 # compute successive differences columnwise as.dat

Re: [R] help with loop

2009-03-12 Thread Nutter, Benjamin
[R] help with loop Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this:   c <- list()   for(i in 1:ncol(mydata)) {   for(j in 2:

[R] help with loop

2009-03-12 Thread Rafael Moral
Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this:   c <- list()   for(i in 1:ncol(mydata)) {   for(j in 2:nrow(mydata)) {   c[[i]] <- s