I'm struggeling to achieve the following (although I already read this vignette):
require(dplyr)
require(lazyeval)
# data looks like
df <- data.frame(col1 = c("entry1", "entry2"), col2 = c("0x12", "0xA1"))
# col1 col2
# 1 entry1 0x12
# 2 entry2 0xA1
# must be something like this:
dots <- list(df %>%
select(col2) %>%
distinct(col2))
df %>%
rowwise() %>%
mutate_(.dots = dots)
# target output
# col1 col2 0x12 0xA1
# 1 entry1 0x12 1 N/A
# 2 entry2 0xA1 N/A 1
So I want to generate a new column which is named after the cell entry and set this to one. This is unlike all other examples I've found so far, where the input columns are dynamically selected (e.g. here) or they're not doing it with dataframe (but a data.table
). If the N/As are a 0
it won't do any harm and save me a postprocessing step.