-1

Is there anyway for R or R-studio to read csv with data column headers that have multiple words with spaces ("dataset A", Eye Color...) as opposed to "EyeColor"? It would be a pain to recreate over 100 column headers without spaces. thanks

I tried using read_csv but it did not work well compared to read.csv

dxw35
  • 1
  • 2
    Welcome to SO, dxw35! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Nov 18 '22 at 15:31
  • 2
    `read.csv` and `read_csv` shouldn't have problems with spaces. Can you make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) what shows what your data actually looks like and the specific problems you are getting trying to read in the data. – MrFlick Nov 18 '22 at 15:32
  • 1
    As it stands, we know nothing about your data (other than a possible top line), `read.csv(text="dataset A,Eye Color\n1,2", check.names=FALSE)` works. – r2evans Nov 18 '22 at 15:32
  • Try the options `sep=','` or `sep=';'`. One of them may work – Yacine Hajji Nov 18 '22 at 15:32

1 Answers1

1

Have you tried read.csv("your.csv", check.names = F)? It should keep the column names with spaces. Bare in mind you will have to use backticks to refer to those columns, e.g. `Eye Color`.

VvdL
  • 2,799
  • 1
  • 3
  • 14