r - Need to replace values of a column with new values -


i need replace column value of data frame new values in r. below example data set:

 date        temp     sf  2/3/2016     20      3  4/3/2016     45      7  7/3/2016     35      8  9/3/2016     25      7  9/4/2016     16      5  9/7/2016     25      7  9/9/2016     14      6  10/2/2016    32      2  11/2/2016    32      2  11/16/2016   45      6 

i need replace value of column "temp" new values c(12,13,14,15) "date" greater (9/7/2016). format of date ("%m/%d%y"). final output should like:

  date        temp     sf  2/3/2016     20      3  4/3/2016     45      7  7/3/2016     35      8  9/3/2016     25      7  9/4/2016     16      5  9/7/2016     25      7  9/9/2016     12      6  10/2/2016    13      2  11/2/2016    14      2  11/16/2016   15      6 

thank you!

we create logical index first converting 'date' column date class , checking whether greater "2016-09-07" ('i1'), subset 'temp' column based on 'i1' , assign values sequence starting 12 , length.out specified sum of 'i1', incremented by 1.

i1 <- as.date(df1$date, "%m/%d/%y") > "2016-09-07" df1$temp[i1] <- seq(12, length.out = sum(i1), = 1) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -