jeckstein
jeckstein

Reputation: 23

Is it possible to create a dataframe that include whitespaces in the column names in R?

I am trying to create a dataframe in R with whitespaces(' ') in the column names. First of all: I know that generally this isn't a good idea. But the dataframe I create is later written to a CSV file and used to upload data to a (poorly designed) system that I am supposed to test. Hence, the column names have to conform to a (poorly designed) template in which columns have names that include whitespaces. I have tried the following:

data.frame('some name' = 'some value')

But this results in a dataframe where the column has the name some.name. I am currently replacing the '.' with ' ' in the CSV file. But this isn't a good workaround since I'll get problems as soon as I start to test with numerical data that includes decimal points.

Can someone help me with this?

Upvotes: 2

Views: 26

Answers (1)

Clemsang
Clemsang

Reputation: 5491

Use check.names:

data.frame('some name' = 'some value', check.names = FALSE)

Upvotes: 3

Related Questions