Problems with importing csv. file

Hello everyone,

I am currently experiencing huge problems reading in a csv file.

The first line looks like this and contains the variable names:

CARD" "AGE" "GENDER" "TAS20It1" "TAS20It2" "TAS20It3" "TAS20It4" "TAS20It5" "TAS20It6" "TAS20It7" "TAS20It8" "TAS20It9" "TAS20It10" "TAS20It11" "TAS20It12" "TAS20It13" "TAS20It14" "TAS20It15" "TAS20It16" "TAS20It17" "TAS20It18" "TAS20It19" "TAS20It20" "SCL1" "SCL2" "SCL3" "SCL4" "SCL5" "SCL6" "SCL7" "SCL8" "SCL9" "SCL10" "SCL11" "SCL12" "SCL13" "SCL14" "SCL15" "SCL16" "SCL17" "SCL18" "SCL19" "SCL20" "SCL21" "SCL22" "SCL23" "SCL24" "SCL25" "SCL26" "SCL27"

The second line contains the values, which are obviously separated by free space:
1 34 2 2 4 1 2 4 5 2 1 3 5 4 2 2 2 2 4 5 5 5 1 0 3 4 0 0 3 2 2 1 4 3 0 0 1 0 0 0 3 1 4 0 2 2 0 0 3 0 4 1 4 3 3 1 4 2 2 1 3 0 0 2 0 1 1 3 1 0 0 0 0 3 0 0 0 4 0 2 0 0 0 2 1 0 2 1 1 0 3 0 0 1 0 0 2 0 2 1 1 1 3 0 0 2 0 1 0 0 0 1 3

I have tried several options including
data0= read.csv("beispiel.csv", header = TRUE, sep ="")
data0= read.csv("beispiel.csv", header = TRUE, sep =" ; ")
data0= read.csv("beispiel.csv", header = TRUE, sep =" , ")

However, nothing seems to be working. The only thing that works is when I copy it to a clipboard but then my R sessions always keeps crashing :frowning:

I am also sending you a screenshot from the

csv. file since it does not contain any real data so there are no data privacy issues.
I would be so so grateful if someone of you could please help me with the import. Thank you so much :slight_smile:

Could you try using read.delim()? Since your data isn't comma-separated, read.csv() isn't the right function for the job.

have you tried sep = " ", as you correctly stated it's an empty space.

Thank you for your suggestions :slight_smile:

When I try to use data0= read.delim("beispiel.csv", header = TRUE, sep = "") the dataset looks "more correct" but somehow additional variables are inserted as can be seen from the screenshot

I have also tried the other suggestion using sep = " " but unfortunately when I use this function with the space in between brackets, I get an error message stating that I have more columns than column names.

Does anyone know how to solve the problem?

Thank you.

Best regards,
Helena

Can you somehow share the file?
Maybe this is exactly the problem, that there are more columns than in the header?
Obviously "read.delim("beispiel.csv", header = TRUE, sep = "")" skips every second header.
Also it what you reported to be the first line contains 50 entries, the second line 113.
I guess some decimal separators got lost in the transition.

I would also recommend uploading the file somewhere (if it can be shared) . Hard to provide a proper solution without some trial and error.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.