Problems importing CSV files

Hi all!

I just started working with R for a few weeks now. But everytime I try to import a dataset that is a CSV file, the variables get weird names (X.. in front of it, while this is not in the CSV file).


RStudio 1-3-2021 19_46_16|690x359
Can somebody tell me how to solve this problem?

I already tried to change the decimal seperator in excell but this does not change a thing. The only normal way for me to import data is if I manually change the (") in the CSV file to (') but I am looking for a way to import data from CSV! without manually mutating the CSV

Your field names in the CSV are quoted, but your data doesn't. That looks unusual.

Even more unusual, it appears they are single and double quoted perhaps.

janitor::clean_names(df)

Would be my starting fix. It has a replace function that I think could replace "X.." with ""

2 Likes

What happens when you just use read.csv() or read_csv from readr instead of using the import function?

1 Like

When I use the normal read.csv, I also get the error "more columns than column names"

So do you then think it is a problem with my excell settings?

If you control the source and the source is excel...

Try removing all the quotes in the file and resaving.

It may be worth opening in an editor (R studio can open as a text file, or notepad) to remove them.

But if the source is extracted from elsewhere, so will recur, then fix in R. Using something like janitor clean names, or a manual renaming or even using colnames with str_replace

colnames(df)<- str_replace("X..", "", colnames(df))

(Where df is the name of your data frame)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.