R Don’t Change Blank to Point when Using data.frame (Example Code)

In this R tutorial you’ll learn how to create a data frame with spaces in the variable names.

Creating Example Data

df_point <- data.frame("col A" = c("F", "Y", "X", "Y"),  # data.frame changes blanks to points
                       "col B" = letters[20:17],
                       "col C" = "o")
df_point
#   col.A col.B col.C
# 1     F     t     o
# 2     Y     s     o
# 3     X     r     o
# 4     Y     q     o

Example: Keep Spaces in Variable Names when Creating Data Frame

df_blank <- data.frame("col A" = c("F", "Y", "X", "Y"),  # Using check.names argument to keep blanks
                       "col B" = letters[20:17],
                       "col C" = "o",
                       check.names = FALSE)
df_blank
#   col A col B col C
# 1     F     t     o
# 2     Y     s     o
# 3     X     r     o
# 4     Y     q     o

Related Tutorials & Further Resources

Please find some additional R programming language tutorials on topics such as indices and merging below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top