I'm assuming the dummy columns are supposed to measure if there is (1) or isn't (0) that number in that column for that row, and not a count.
There's probably a more elegant way to do this, but it works:
library(tidyverse)
orig <- tribble(
~column1, ~column2,
1, 0,
3, 2,
0, 4,
1, 2 # Added to show case with repeated #s
)
# This starts with the input table...
orig %>%
# adds new columns based on the same table
cbind(orig) %>%
rowid_to_column() %>%
# make into long format and combine col name and value
gather(col, value, column1:column2) %>%
filter(value != 0) %>%
mutate(col2 = paste(col, value, sep = "_")) %>%
# I presume desired output should show 1
# in rows where that value is found, 0 if not
mutate(value = 1) %>%
select(-col) %>%
spread(col2, value, fill = 0) %>%
select(-rowid) # Needed this to be last to keep row order
#> column1.1 column2.1 column1_1 column1_3 column2_2 column2_4
#> 1 1 0 1 0 0 0
#> 2 3 2 0 1 1 0
#> 3 0 4 0 0 0 1
#> 4 1 2 1 0 1 0
Created on 2018-07-10 by the reprex package (v0.2.0).