Split aggregated data table into multiple CSV files

Smajl

I have a data table with may rows containing data about usage of some specific services. This data describes the usage of different service types in different regions:

type     region     quantity     timestamp
small     A            2         05/01/15
small     B            1         05/01/15
big       A            1         05/01/15
small     A            2         06/01/15
small     B            1         06/01/15
big       A            3         06/01/15
...etc

I am performing some operations over the data series of every unique combination of type and region (each of these combinations produce its own time series so small-A should be treated independently from small-B, for example)

I already figured out how to do these kind of operations with aggregated data like this:

aggregatedDT <- DT[, .(quant = sum(quantity)), by = .(week, region,type)]

Now I need to save each data series into a separate CSV file. I am not sure if there are some built-in functionality to do such operation so I would like to know whether this is even possible.

My desired output would be:

small-A.csv:

week1: total quantity
week2: total quantity
...

And the same thing for small-B.csv, big-A.csv etc. Athe the moment, I have these data in one aggregated data.table but these csv files are meant as an input for another algorithm which needs to take the timeseries one by one.

Heroka

You could try something like this to stay 'inside' data.table, while generating the appropriate filenames:

aggregatedDT[,write.csv(.SD,file=sprintf("%s-%s.csv", unique(type),unique(region))),
             by=.(region,type)]

Data used:

aggregatedDT <- data.table(expand.grid(week=1:2, region=c("A","B"),type=c("big","small")),
                           quant=1:8)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Split multiple CSV files in batch

From Dev

How to split csv file into multiple files by size

From Dev

How to split CSV file and create multiple CSV files based on a column

From Dev

How to split CSV file and create multiple CSV files based on a column

From Dev

Split data in r and save all the split files in csv

From Dev

How to split csv files into multiple files using the delimiter? python

From Dev

split column in data.table to multiple rows

From Dev

data.table - split multiple columns

From Dev

Import multiple csv files into one table

From Dev

php: importing multiple csv files into mysql table

From Dev

Split CSV to Multiple Files Containing a Set Number of Unique Field Values

From Dev

How to split a CSV file into multiple files based on column value

From Dev

How to split a CSV file into multiple files based on a text string?

From Dev

split large csv file into multiple small files in perl

From Dev

Read multiple csv data files and sort the data into a new csv file

From Dev

Pooling data from multiple csv files into a cell

From Dev

Efficient method for matching data in multiple csv files

From Dev

Filtering CSV data into multiple separate files

From Dev

Parsing data from multiple text files into a CSV

From Dev

export multiple table data into csv file in oracle

From Dev

Text-Widget Applied to an aggregated data table

From Dev

Split a text file according to data into multiple files in Unix

From Dev

Split a text file according to data into multiple files in Unix

From Dev

Finding the Count for a String on Multiple Zipped Files in Multiple Directories (non aggregated)

From Dev

Create a table from the frequencies of taxa found in multiple CSV files

From Dev

Create table with frequency of unique names retrieved from multiple .csv files

From Dev

Create a table from the frequencies of taxa found in multiple CSV files

From Dev

Can multiple collections of NetCDF files be aggregated using NcML?

From Dev

Split csv files based on columns

Related Related

  1. 1

    Split multiple CSV files in batch

  2. 2

    How to split csv file into multiple files by size

  3. 3

    How to split CSV file and create multiple CSV files based on a column

  4. 4

    How to split CSV file and create multiple CSV files based on a column

  5. 5

    Split data in r and save all the split files in csv

  6. 6

    How to split csv files into multiple files using the delimiter? python

  7. 7

    split column in data.table to multiple rows

  8. 8

    data.table - split multiple columns

  9. 9

    Import multiple csv files into one table

  10. 10

    php: importing multiple csv files into mysql table

  11. 11

    Split CSV to Multiple Files Containing a Set Number of Unique Field Values

  12. 12

    How to split a CSV file into multiple files based on column value

  13. 13

    How to split a CSV file into multiple files based on a text string?

  14. 14

    split large csv file into multiple small files in perl

  15. 15

    Read multiple csv data files and sort the data into a new csv file

  16. 16

    Pooling data from multiple csv files into a cell

  17. 17

    Efficient method for matching data in multiple csv files

  18. 18

    Filtering CSV data into multiple separate files

  19. 19

    Parsing data from multiple text files into a CSV

  20. 20

    export multiple table data into csv file in oracle

  21. 21

    Text-Widget Applied to an aggregated data table

  22. 22

    Split a text file according to data into multiple files in Unix

  23. 23

    Split a text file according to data into multiple files in Unix

  24. 24

    Finding the Count for a String on Multiple Zipped Files in Multiple Directories (non aggregated)

  25. 25

    Create a table from the frequencies of taxa found in multiple CSV files

  26. 26

    Create table with frequency of unique names retrieved from multiple .csv files

  27. 27

    Create a table from the frequencies of taxa found in multiple CSV files

  28. 28

    Can multiple collections of NetCDF files be aggregated using NcML?

  29. 29

    Split csv files based on columns

HotTag

Archive