Suppose I have the following dataset:
data = tibble::tibble(
id = c("x", "y", "x"),
inputA = c(1, NA, NA),
inputB = c(2, 1, NA),
inputC = c(3, 2, 3)
)
Which looks like this:
# A tibble: 3 x 4
id inputA inputB inputC
<chr> <dbl> <dbl> <dbl>
1 x 1 2 3
2 y NA 1 2
3 x NA NA 3
And I want to create a variable for each id (each unique row) which identifies what input the id has. I mean, the new variable should indicate what input the id has if the input variable isn't missing (NA).
The desired output should look like this:
# A tibble: 3 x 5
id inputA inputB inputC inputs
<chr> <dbl> <dbl> <dbl> <chr>
1 x 1 2 3 inputA-inputB-inputC
2 y NA 1 2 inputB-inputC
3 x NA NA 3 inputC
The variable I want to create is inputs