0

I am trying to do an in-place replacement of my df with the following conditions:

  1. the storm name must match
  2. the landfall date must be the same year, and the date is formatted as YYYYMMDD

When just checking for individual conditions, I do get the correct behavior with the code below:

orig_county_rows$landfall_date[orig_county_rows$Storm_Name == stormName] <- l_date

and

orig_county_rows$landfall_date[grepl(year, orig_county_rows$date)] <- l_date

However, when I combine them like

orig_county_rows$landfall_date[(orig_county_rows$Storm_Name == stormName) && (grepl(year, orig_county_rows$date))] <- l_date

no rows are updated. Does anyone see what I am doing wrong here? Thanks!

Alan
  • 389
  • 3
  • 16
  • 3
    Can't answer without a reproducible example, but did you try a single ampersand and no parentheses? – Bill O'Brien Sep 08 '19 at 21:51
  • 4
    You should use only one `&` to compare element by element, `&&` will only compare the first elements, see: https://stackoverflow.com/questions/16027840/whats-the-differences-between-and-and-in-r – Chelmy88 Sep 08 '19 at 22:05
  • The single ampersand made the fix - thanks @BillO'Brien and @Chelmy88! – Alan Sep 09 '19 at 00:26

0 Answers0