I want to replace strings in an R dataframe. The dataframe shows per production order (rows) when a resource / production step (columns) was utilized. For this particular analysis the time values are not needed, instead I want to have the column name in place of the timestamp.
The data looks something like this
df_current <- data.frame(
Prod.order = seq(123, 127),
B100 = c("01:00:00", "02:00:00", "03:00:00", "04:00:00", "05:00:00"),
`B100 (2)` = c(NA, NA, "06:00:00", "07:00:00", NA),
D200 = c("02:00:00", NA, NA, NA, "06:00:00"),
D300 = c(NA, NA, "04:00:00", "05:00:00", "07:00:00"),
check.names = FALSE)
And i want it to look like this. (Also i want to remove the NA's but this isnt a problem)
df_desired <- data.frame(
Prod.order = seq(123, 127),
B100 = c("B100", "B100", "B100", "B100", "B100"),
`B100 (2)` = c("", "", "B100 (2)", "B100 (2)", ""),
D200 = c("D200", "", "", "", "D200"),
D300 = c("", "", "D300", "D300", "D300"),
check.names = FALSE)
It seems so simple but I havn't been able figure it out. p.s. it would be amazing if the solution fits in a dplyr pipline ;)
Thanks :D
check.names = FALSEto your reproducible data; otherwise, the names of the variables in the data frame are checked to ensure that they are syntactically valid.