Rename chr value

I would like to rename chr label in a column :

df %>% 
  filter(station  == A1 & date == "xxxx-xx-xx")

I would like to rename the name of this station according to this filter.
I have infact several station named A1 but not having the same date. So I would like to rename these names
But I don't know what to do after this code

I would make a new column by doing something like df %>% dplyr::mutate(unique_station_date = paste(station, date, sep = '_')). Then you can use tidyr::pivot_wider on that new column to transform that column to names. There may be a better way to do this, but without a sample of your data it's hard to know.

1 Like

Thanks for your response !
Here an example of my df :

Station  Date    Depth
  A1  2021/05/14  250
  A1  2021/05/19  250 
  A2  2021/10/05  360
  A3  2021/08/16  360
  A4  2021/09/04  410
  A4  2021/09/04  230

So I want to distinct all my station considering the others column. Like the station A1 I want have A1(a) and A1(b) because they don't have the same date, I want A4(a) and A4(b) because they don't have the same depth.
And I have others differences like that

I don't understand how work your function ?

Thanks a lot

The following solution will be fine so long as no Station has more than 26 Dates associated, as then we would run out of letters a-z


(df_1 <- tibble::tribble(
  ~Station,        ~Date, ~Depth,
      "A1", "14/05/2021",   250L,
      "A1", "19/05/2021",   250L,
      "A2", "05/10/2021",   360L,
      "A3", "16/08/2021",   360L,
      "A4", "04/09/2021",   410L,
      "A4", "04/09/2021",   230L

(df_2 <- group_by(df_1,
                  Station) |> 
    mutate(unique_station_name =ifelse(n()>1,
1 Like

Great, thank you !
How to make it apply only to specific columns?
For example if I have columns of environmental variables and I only want to distinguish my stations in relation to the date, depth and time columns for example?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.