0

I'm wondering why below code isn't updating the parent table of ra2021. Am I using the Mutate and pipe incorrectly here? For the filtered time period, I wanted to change the value to zero. The console window shows the updated value (zero) but this is not reflecting in the parent table. Thanks.

ra2021 %>% 
  filter(TIMESTAMP > ymd_hms("2021-09-27 16:22:00") & TIMESTAMP < ymd_hms("2021-10-08 11:38:00"))%>% 
  mutate(Rf=0)
  • It's because you don't appear to be assigning the result of the mutation to `ra2021`. So the original dataframe is unchanged. – Limey Aug 18 '22 at 12:13
  • @Limey - Could you advise how I do that? Thanks. – Aravindan Kalai Aug 18 '22 at 12:14
  • just put ``ra2021 =`` before – user438383 Aug 18 '22 at 12:15
  • Really???? `ra2021 <- ra2021 %>% filter(...`. – Limey Aug 18 '22 at 12:15
  • @Limey - This changes all the value of column Rf in the table ra2021 to zero. I'd like to update the changes only to the filter as ra2021 has more records outside the filter. Thanks. – Aravindan Kalai Aug 18 '22 at 12:21
  • 1
    Please provide an example of your dataset, `dput(head(ra2021))` – Basti Aug 18 '22 at 12:30
  • That's not the question you asked. Your sample code filtered the dataset before mutating. That's not the same as conditionally editing *some* of the values in the original data frame. The "conditional editing" problem has been asked and answered hundreds, possibly thousands, of times on stackoverflow. For example, [here](https://stackoverflow.com/questions/22337394/dplyr-mutate-with-conditional-values). – Limey Aug 18 '22 at 12:42
  • @Limey - I shall take a look at those keywords and the example. – Aravindan Kalai Aug 18 '22 at 13:03

0 Answers0