I have duplicated a set of data, and I'd like to edit the rows I have duplicated by adding an 'A' to the duplicated rows and 'a' to the original rows under the column "Code". Example below.
The reproducible data frame:
Date <- c("2016-01-02","2016-01-03","2016-01-04")
Data <- c("0",".2", ".1")
Code <- c("", "", "")
y <- data.frame(Date, Data, Code)
y<- y[rep(row.names(y),2),]
y$Date <- as.Date(y$Date, format='%Y-%m-%d')
y <- y[order(y$Date), ]
The current data:
> y
Date Data Code
1 2016-01-02 0
1.1 2016-01-02 0
2 2016-01-03 .2
2.1 2016-01-03 .2
3 2016-01-04 .1
3.1 2016-01-04 .1
Desired outcome:
> y
Date Data Code
1 2016-01-02 0 a
1.1 2016-01-02 0 A
2 2016-01-03 .2 a
2.1 2016-01-03 .2 A
3 2016-01-04 .1 a
3.1 2016-01-04 .1 A