I have a dataframe that looks like this:
structure(list(INVOICE_ID = 7367109:7367117, Edible = c("Edible",
NA, NA, NA, NA, NA, NA, NA, "Edible"), Vape = c("Vape", NA, NA,
NA, NA, NA, NA, NA, NA), Flower = c(NA, "Flower", "Flower", "Flower",
"Flower", "Flower", "Flower", "Flower", "Flower"), Concentrate = c(NA,
NA, NA, "Concentrate", NA, NA, NA, NA, NA)), row.names = c(NA,
-9L), class = c("tbl_df", "tbl", "data.frame"))
How do I shift the items left so that there are no holes in the dataframe? I'd like the output to look like this, where different kinds of items could be stacked in the same column. The first column would always be filled out; the second column may or may not be, etc. The NA
values will always be on the right.
output <- tribble(
~INVOICE_ID, ~Item_1, ~Item_2, ~Item_3, ~Item_4,
"7367109", "Edible", "Vape", NA, NA,
"7367110", "Flower", NA, NA, NA
)