R data.table overwriting column after grouping operation

59 views Asked by At

After selection of rows with .SD[.N] I can't convert column because of different number of elements then there are :

library(data.table)

dane = structure(list(DATA_CZAS = c("2010-08-20 10:24:03", "2010-10-11 15:39:29",
"2010-12-10 13:40:31", "2011-02-03 11:53:51", "2011-02-03 11:57:06",
"2011-03-15 15:17:30", "2011-03-29 09:41:57", "2011-09-19 10:16:49",
"2011-11-24 15:54:34", "2012-12-10 17:18:50", "2012-12-10 17:30:11"
), KOD_ISIN = c("AT0000A00BF2", "AT0000A00BF2", "AT0000A00BF2",
"AT0000A00BF2", "AT0000A00BF2", "AT0000A00BF2", "AT0000A00BF2",
"AT0000A00BF2", "AT0000A00BF2", "AT0000A00BF2", "AT0000A00BF2"
), KURS = c(42.69, 41.82, 42.01, 45.4, 44.6, 43.45, 45.98, 37.43,
35.01, 33.34, 32.28), WOLUMEN = c(12L, 50L, 12L, 78L, 45L, 24L,
33L, 60L, 110L, 1L, 1L)), class = "data.frame", row.names = c(NA,
-11L))

dane = data.table(dane)

dane$DATA_CZAS <- as.POSIXlt(dane$DATA_CZAS)

dane[,DATA_CZAS:=as.double(dane$DATA_CZAS) - as.double(dane$DATA_CZAS)%%(15*60)+15*60]

print(as.POSIXlt(dane$DATA_CZAS, origin = "1970-01-01", tz = "Europe/Warsaw"))
 [1] "2010-08-20 10:30:00 CEST" "2010-10-11 15:45:00 CEST"
 [3] "2010-12-10 13:45:00 CET"  "2011-02-03 12:00:00 CET" 
 [5] "2011-02-03 12:00:00 CET"  "2011-03-15 15:30:00 CET" 
 [7] "2011-03-29 09:45:00 CEST" "2011-09-19 10:30:00 CEST"
 [9] "2011-11-24 16:00:00 CET"  "2012-12-10 17:30:00 CET" 
[11] "2012-12-10 17:45:00 CET" 

dane <- dane[,.SD[.N],by=list(DATA_CZAS)]

    
> dane[,DATA_CZAS:=as.POSIXlt(DATA_CZAS, origin = "1970-01-01", tz = "Europe/Warsaw")]
Błąd w poleceniu '`[.data.table`(dane, , `:=`(DATA_CZAS, as.POSIXlt(DATA_CZAS, ':
  Supplied 11 items to be assigned to 10 items of column 'DATA_CZAS'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.

> dane$DATA_CZAS <- as.POSIXlt(dane$DATA_CZAS, origin = "1970-01-01", tz = "Europe/Warsaw")
Błąd w poleceniu 'set(x, j = name, value = value)':
  Supplied 11 items to be assigned to 10 items of column 'DATA_CZAS'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.

> packageVersion("data.table")
[1] ‘1.13.0’
0

There are 0 answers