I read this question about reshape and I tryed to use on my dataset.
But when I use it, my new dataset doen't have all the column requested and repeat some variables.
My actual dataset is like this:
a1 <- c("10/10/2023 00:00:08","10/10/2023 00:00:08","10/10/2023 00:00:08", "10/10/2023 00:00:08", "10/10/2023 00:00:16", "10/10/2023 00:00:16", "10/10/2023 00:00:16", "10/10/2023 00:00:16")
b1 <- c(7, 7, 7,5, 4, 4, 3, 3)
c1 <- c("A","B", "C", "D", "A", "B", "C", "D")
m1 <- data.frame(a1, b1, c1)
and I want something like this:
time <- c("10/10/2023 00:00:08","10/10/2023 00:00:16")
A <- c(7, 4)
B <- c(7, 4)
C <- c(7, 3)
D <- c(5, 3)
m <- data.frame(time, A, B, C, D)
my actual code is this, and for this example it works:
reshape(m1, idvar = "a1", timevar = "c1", direction = "wide")
In my original dataset i have more variables than the example dataset. It is a problem? How can I fix it?
Even though what you show above is working, the full function should be as:
reshape(m1, idvar = "a1", timevar = "c1", v.names=c("b1"), direction = "wide")
You should always make sure you include v.names
parameter for all the variables that will become multiple columns in wide format. This maybe the reason why "your full data set doesn't have all the columns after reshaping"