I have a sample data which looks like
Dput:
structure(list(variable = structure(c(1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L), .Label = c("firstname", "lastname", "title"), class = "factor"),
value = structure(c(6L, 2L, 5L, 1L, 3L, 5L, 7L, 8L, 4L), .Label = c("adam",
"dingler", "jhon", "miss", "mr", "naji", "stephanie", "williams"
), class = "factor")), .Names = c("variable", "value"), class = "data.frame", row.names = c(NA,
-9L))
I want to transform this to wide format so that it looks like :
I tried
library(tidyr)
final_data <- spread(sample, key = variable, value = value)
but i am getting output not in the desired format, i am getting output in this format:
I need help how can get rid of the NA'S and restructure the output in desired format.