I was wondering how I can edit my data frame. I have a data frame like the one below.
ID Value
A1_5 5.6
A2_7 3.4
A3_8 6.7
I want to duplicate the IDs by changing the first letter, and repeating the same value since they are coming from the same samples. So I want to create a data frame such as…
ID Value
A1_5 5.6
B1_5 5.6
A2_7 3.4
B2_7 3.4
A3_8 6.7
B3_8 6.7
How can I go about doing this?
Thank you in advance.
>Solution :
library(dplyr)
data %>%
mutate(
ID = stringr::str_replace(ID, 'A', 'B')
) %>%
bind_rows(data)