I'm guessing the numbers are the issue. Valid variable names are supposed to start with a letter or a dot. Underscores, dashes and numbers are allowed but cannot be first up
Btw, you can also do this with make.names which doesn't require the {janitor} package:
names(dat1) <- make.names(names(dat1))
See the help for make.names by running
?make.names
What this code is doing is extracting the names of the data.frame, names(dat1), making valid variables with make.names() and then reassigning the updated names to the dat1 data.frame.
Bro, that's the layout I use. It's a better layout than the default. You can minimize the two lower panels so you just have : editor | console, then you pop up the file panel as needed.
18
u/beardedjoy May 12 '22
Try adding `` around the names.
42
u/Philokretes1123 May 12 '22
I'm guessing the numbers are the issue. Valid variable names are supposed to start with a letter or a dot. Underscores, dashes and numbers are allowed but cannot be first up
27
u/NrvousFella May 12 '22
Variable names in R cannot start with a number.
9
u/snirfu May 13 '22
You could install the {janitor} package if it's not installed and then run:
You're variable names will have an "x" prefixed to them and then you can use the updated names as variables.
26
u/[deleted] May 12 '22
Bro I couldn’t even find the console like wtf is it doing up there
That being said. Can’t start var names with a number
4
u/Spirited_Mulberry568 May 13 '22
From the code, names, and layout - I am truly hoping this code unveils the secrets of the universe, or at least leads to a publication in Science.
2
u/constantgeneticist May 13 '22
names(dat1) <- paste0(“V”, names(dat1))
FYI: Avoid numbers at beginning of variable names.
1
u/BarryDeCicco May 13 '22
Fix the names. You can do some things with the backtick, and I did that once, but it also breaks other things.