Re: [R] if else for cumulative sum error

2014-12-03 Thread Jefferson Ferreira-Ferreira
ogy > Texas A&M University > College Station, TX 77840-4352 > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David > Winsemius > Sent: Tuesday, December 2, 2014 2:50 PM > To: Jefferson Ferreira-Ferreira > Cc: r-help

Re: [R] if else for cumulative sum error

2014-12-02 Thread David L Carlson
ege Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Tuesday, December 2, 2014 2:50 PM To: Jefferson Ferreira-Ferreira Cc: r-help@r-project.org Subject: Re: [R] if else for cumulative sum error On Dec 2, 2014, at 12:26 PM

Re: [R] if else for cumulative sum error

2014-12-02 Thread David Winsemius
On Dec 2, 2014, at 12:26 PM, Jefferson Ferreira-Ferreira wrote: > Thank you for replies. > > David, > > I tried your modified form > > for (i in 1:seq_along(rownames(dadosmax))){ No. it is either 1: or seq_along(...). in this case perhaps 1:(nrow(dadosmax)-44 would be safer You do not

Re: [R] if else for cumulative sum error

2014-12-02 Thread Jefferson Ferreira-Ferreira
Thank you for replies. David, I tried your modified form for (i in 1:seq_along(rownames(dadosmax))){ dadosmax$enchday[i] <- if ( (sum(dadosmax$above[i:(i+44)])) >= 45) 1 else 0 } However, I'm receiving this warning: Warning message: In 1:seq_along(rownames(dadosmax)) : numerical expression

Re: [R] if else for cumulative sum error

2014-12-02 Thread John McKown
On Tue, Dec 2, 2014 at 12:08 PM, Jefferson Ferreira-Ferreira < jeco...@gmail.com> wrote: > Hello everybody; > > I'm writing a code where part of it is as follows: > > for (i in nrow(dadosmax)){ > dadosmax$enchday[i] <- if (sum(dadosmax$above[i:(i+44)]) >= 45) 1 else 0 > } > ​Without some test d

Re: [R] if else for cumulative sum error

2014-12-02 Thread David Winsemius
On Dec 2, 2014, at 10:08 AM, Jefferson Ferreira-Ferreira wrote: > Hello everybody; > > I'm writing a code where part of it is as follows: > > for (i in nrow(dadosmax)){ > dadosmax$enchday[i] <- if (sum(dadosmax$above[i:(i+44)]) >= 45) 1 else 0 > } > > That is for each row of my data frame, su

[R] if else for cumulative sum error

2014-12-02 Thread Jefferson Ferreira-Ferreira
Hello everybody; I'm writing a code where part of it is as follows: for (i in nrow(dadosmax)){ dadosmax$enchday[i] <- if (sum(dadosmax$above[i:(i+44)]) >= 45) 1 else 0 } That is for each row of my data frame, sum an specific column (0 or 1) of that row plus 44 rows. If It is >=45 than enchday