This is piggy backing on a question I answered last night as I am reconsidering how I\'d like to format my data. I did search but couldn\'t find up with any applicable answe
You can reshape to long format, drop the blank entries and then go back to wide:
res <- dcast(melt(df, id.vars = "record_numb")[ value != "" ], record_numb ~ variable)
record_numb col_a col_b col_c
1: 1 123 234 543
2: 2 987 765 543
You may find it more readable at first using magrittr:
library(magrittr)
res = df %>%
melt(id.vars = "record_numb") %>%
.[ value != "" ] %>%
dcast(record_numb ~ variable)
The numbers are still formatted as strings, but you can convert them with...
cols = setdiff(names(res), "record_numb")
res[, (cols) := lapply(.SD, type.convert), .SDcols = cols]
Type conversion will change each column to whatever class it looks like it should be (numeric, integer, whatever). See ?type.convert.