1
Hi, how are you?
I’m having trouble using the function spread()
: it shows error and does not pop.
dados<-structure(list(V1 = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), class = "Date"),
EST = c("EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST01", "EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST01", "EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST01", "EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST01", "EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST01", "EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST01", "EST01", "EST01", "EST01", "EST01", "EST01", "EST01",
"EST02", "EST02"), TT = new("Period", .Data = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0), year = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), month = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0), day = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), hour = c(0,
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17,
17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 0, 0),
minute = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
variable = c("SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB", "SensorA", "SensorB",
"SensorA", "SensorB", "SensorA", "SensorB"), valor = c(0.013,
-0.073, 0.018, -0.125, 0.022, -0.169, 0.019, -0.154, 0.019,
-0.144, 0.021, -0.154, 0.021, -0.186, 0.021, -0.181, 0.021,
-0.203, 0.021, -0.189, 0.023, -0.185, 0.027, -0.211, 0.049,
-0.196, 0.08, -0.048, 0.049, 0.17, 0.026, 0.223, 0.036, 0.312,
0.045, 0.386, 0.041, 0.431, 0.031, 0.424, 0.022, 0.389, 0.028,
0.308, 0.042, 0.156, 0.021, 0.078, 0.013, -0.073)), class = "data.frame", row.names = c(NA,
-50L))
when I try to use:
dados%>%spread(variable,valor)
he of error:
Error: Each Row of output must be identified by a Unique Combination of Keys. Keys are Shared for 48 Rows:
- 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47
- 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48
Run
rlang::last_error()
to see Where the error occurred.
I needed him to do what this function is doing, namely to unpack: (I know that the variable column was duplicated and so he added. x and . y)
I understand that there is duplication of information because it is only popping by the variable column, in this case how to paste more columns, see that in the function merge()
for two subset()
i used more reference columns.
merge(subset(dados%>%rename(`SensorA`=valor),variable=="SensorA"),subset(dados%>%rename(`SensorB`=valor),variable=="SensorB"), by=c("V1","EST","TT"))