The latest version of R (version.string R version 3.6.3 (2020-02-29) reads Excel files without inserting a period in place of spaces in some headers. This causes a problem when using the subset function: subset(data, column one =1) as opposed to subset(data, column.one=1). My work around has been to rename the columns used for sub setting, inserting the periods. Is there a better way?
Asked
Active
Viewed 51 times
-1
-
Thank you for your response. I have been using the readxl package. names(df)<-make.names(names = names(df), unique = T) worked! – datatooinfo Mar 28 '20 at 18:49
-
1It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. R has never directly read Excel files. There are (several) packages that can do that. They may each work differently depending on how you call them. It's unclear what's going on without actually seeing the code you are running. – MrFlick Mar 28 '20 at 20:30
-
Problem resolved using names(df)<-make.names(names = names(df), unique = T) . Thank you for your comment. – datatooinfo Mar 29 '20 at 12:32
1 Answers
0
How do you read in your excel sheets?
Are you using the xlsx -package ? It has alot of options
install.packages("xlsx")
library("xlsx")
otherwise using base R you can fix colum names by
names(df)<-make.names(names = names(df), unique = T)
or using tribble
new_df<-tibble(df, .name_repair = "universal")
an then convert back to csv /xlsx

user12256545
- 2,755
- 4
- 14
- 28
-
Thank you for your response. I have been using the readxl package. names(df)<-make.names(names = names(df), unique = T) worked! – datatooinfo Mar 28 '20 at 18:52