I have following dataset
group <- c(rep("X1",5), rep("X3",5))
set.seed(1)
value <- c(rep(rnorm(1,.6,.2),5),rep(rnorm(1,.5,.2),5))
time <- c("2018-07-01 00:00:00", "2018-07-01 01:00:00",
"2018-07-01 02:00:00", "2018-07-01 03:00:00",
"2018-07-01 04:00:00", "2018-07-01 00:00:00",
"2018-07-01 01:00:00", "2018-07-01 03:00:00",
"2018-07-01 04:00:00", "2018-07-01 05:00:00")
country <- c("HU", "ZA", "XX", "ZZ", "RO", "HU", "ZA", "XX", "ZZ", "RO")
dat <- data.frame(time, country, group,value)
I want country
values are transformed into columns and time
column showing all unique values (no duplicates for this column). How can I do it?
I found here different solutions How to reshape data from long to wide format , however I need to un-melt based on two columns, so could not figure out how to do it. I.e. i tried
dcast(dat, group,time ~ country, value.var = "value")
question from:
https://stackoverflow.com/questions/65939587/how-unmelt-the-data-in-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…