I have the following data:
dat <- data.frame(sheet = c("a", "b", "c"),
condition1 = c("k", "l", "m"),
condition2 = c("x", "y", "z"))
I now want to create a new column using the tidyverse that concatenastes these columns. However, I always get an error.
library(tidyverse)
new_dat %>%
rowwise() %>%
mutate(marker = str_c(c_across(c(sheet, starts_with("condition"))), sep = "/")) %>%
ungroup()
Error: Problem with `mutate()` input `marker`.
x Input `marker` can't be recycled to size 1.
i Input `marker` is `str_c(c_across(c(sheet, starts_with("condition"))), sep = "/")`.
i Input `marker` must be size 1, not 3.
i Did you mean: `marker = list(str_c(c_across(c(sheet, starts_with("condition"))), sep = "/"))` ?
i The error occurred in row 1.
Any suggestion/help?
Expected output:
sheet condition1 condition2 marker
1 a k x a/k/x
2 b l y b/l/y
3 c m z c/m/z
Note: I alyo tried the code without using the rowwise part and using across instead of c_across (and adapting the syntax for across), but I'm getting a similar error. Replacing str_c by paste0 also doesn't work.
EDIT: deleted the x column from the input data since it doesn't add any value.