Hardly. DF$wyear is a vector, but it is being treated as though it is a scalar. Read Bert's response. -- Sent from my phone. Please excuse my brevity.
On July 4, 2017 11:17:24 AM PDT, Rui Barradas <ruipbarra...@sapo.pt> wrote: >Hello, > >You have a '{' too many. > >for(i in 1972:1985){ > if(DF$year==i & DF$month %in% 1:9){ > DF$wyear <- i > }else{ > DF$wyear < i-1 > } > } > } > >I believe this is it. > >Hope this helps, > >Rui Barradas > >Em 04-07-2017 19:31, lily li escreveu: >> Hi R users, >> I have a question about adding a column for water year. The dataframe >has >> the structure below. But the wyear column just shows one year. Could >anyone >> help me with this problem? Thanks. >> >> DF >> year month day time flow >> 1972 1 1 1972-01-01 5 >> 1972 1 2 1972-01-02 5.5 >> 1972 1 3 1972-01-03 6 >> ... >> 1985 12 31 1985-12-31 6 >> >> >> for(i in 1972:1985){ >> if(DF$year==i & DF$month %in% 1:9){ >> DF$wyear <- i { >> }else{ >> DF$wyear < i-1 >> } >> } >> } >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > >______________________________________________ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.