I have a .csv file in the following format:
Date , Time , Value
1899-01-01 , 4:00:00 , 1
1899-01-01 , 4:01:00 , 2
1899-01-01 , 4:02:00 , 3
1899-01-01 , 4:03:00 , 4
1899-01-01 , 4:04:00 , 5
1900-08-22 , 22:00:00 , 101
1900-08-22 , 22:01:00 , 102
2013-08-29 , 4:00:00 , 1000
2013-02-29 , 4:02:00 , 1001
2013-02-29 , 4:03:00 , 1002
Is it possible to group by date
to produce a data.table
in the the following format:
Date , Vector(variable length)
1899-02-28, c(1,2,3,4,5)
1900-08-22, c(101,102)
1900-08-22, c(1000,1001,1002)
This is the best that I have so far (after a day of attempts):
raw <- read.csv(pathName, header = TRUE, stringsAsFactors = FALSE)
groupedByDate <- split(raw, raw$Date)
However, this seems to produce a very wide table with one column for each date, which is not very close to what I want.
Use
aggregate
andpaste0
What about using
aggregate
on adata.frame
named "mydf" as follows:The "Value" column is now a
list
which contains your vectors.What you were probably looking for with
split
is: