Reputation: 1610
I have a .CSV file contains multiple data frames. It looks like this:
# A;Date;Price;Volume;Country
# B;Company;Available;StartDate;EndDate;Published;Modified
# C;ID;Timestamp;Capacity
# D;Rownumbers
#
A;2016-01-01 00:00:00;75.18;2500;DK
A;2016-01-01 00:00:00;55.25;8500;DE
A;2016-01-01 00:00:00;125.00;6500;UK
A;2016-01-01 01:00:00;65.28;2400;DK
# A; etc....
B;PRETZELS;TRUE;2016-01-01;2016-01-02;YES;2016-01-03
B;FAKES;FALSE;2016-01-01;2016-01-02;NO;2016-01-03
# B; etc....
C;11;2016-01-01 23:00:00;25
C;16;2016-01-01 22:00:00;15
# C; etc....
D;1175
So, the first part of the file contains information about the data in the file. From this you can see that depending on the information - there is a different number of columsn. In this case from A - D.
I've tried doing :
df <- read.table(file = x.csv, sep = ";", fill = TRUE)
But fill can't take care of a different number of columns - if you increase the number of columns later on for example.
Ideally, I would either create a number of data frames - based on the row name (such as A, B, C and D) in this case.
Or just have data frame with column-numbers = max(ncols(df))
with a lot of NA
values I could then filter out to indivdual data frames later. Ie. just read everything in, with a specification of number of columns.
Upvotes: 0
Views: 130
Reputation: 3833
df <- read.delim(file.choose(),header=F,sep=";",fill=TRUE) # choose x.csv from you PC.
file.choose() opens up a dialog box for selecting the input file. Hope this helped.
Upvotes: 1