In this dataframe df of 1 column X the value a is occuring multiple times:
dataframe:
df <- structure(list(col = c("<NA>", "<NA>", "a", "<NA>", "<NA>", "<NA>",
"a", "<NA>", "<NA>", "<NA>", "<NA>", "<NA>", "a", "<NA>", "<NA>",
"a", "<NA>", "<NA>", "a", "<NA>", "<NA>", "a", "<NA>")), class = "data.frame", row.names = c(NA,
-23L))
I would like to rename the first a as start and the second a as end and the next a again as start and the next a as end and so on....
desired output:
df1 <- structure(list(col = c("<NA>", "<NA>", "start", "<NA>", "<NA>",
"<NA>", "end", "<NA>", "<NA>", "<NA>", "<NA>", "<NA>", "start",
"<NA>", "<NA>", "end", "<NA>", "<NA>", "start", "<NA>", "<NA>",
"end", "<NA>")), class = "data.frame", row.names = c(NA, -23L
))
Many thanks!!!