0

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.

1 Answer 1

1
 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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.