0

I used RBIND to stack 3 datasets no column names: combined <- rbind(df1, df2, df3)

It worked fine.

It assigned X1, X2 and X3 to the columns.

I renamed the columns using:

names(combineddf)[names(combineddf)=="X1"] <- "date"

I used head(combineddf) to verify it worked. I see the new "date" name.

But where I reference "date" I get an error.

When I do str(combineddf) I still see X1, X2 X3.

How do I fix this, and why is R doing this?

Andre Wildberg
  • 12,344
  • 3
  • 12
  • 29
  • 1
    How did you *'reference "date"'*? What was the error you got? *"When I do str(combineddf) I still see X1, X2 X3"* That doesn't sound right. If the `head()` verification worked, then the `str()` verification should be in alignment. Are you sure you don't have two copies of this data with slightly different names or something? Or maybe you re-ran earlier lines of code and didn't also run the name reassignment? – Gregor Thomas Jan 31 '23 at 16:40
  • `date` will not be an object in its own right. So saying you "referenced "date" suggests you should instead have been "referencing" `combineddf$date` or perhaps `combined$date` since you used two different names. – IRTFM Jan 31 '23 at 16:41
  • It'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. – MrFlick Jan 31 '23 at 16:59
  • happy to include an example but it is reading a csv. – Sabor James Jan 31 '23 at 17:01
  • If it helps, the STR shows: - attr(*, "spec")= .. cols( .. X1 = col_character(), .. X2 = col_character(), .. X3 = col_character(), .. X4 = col_character() .. ) - attr(*, "problems")= – Sabor James Jan 31 '23 at 17:15
  • right now, I solved it by exporting a csv, reading it back into R, and using the original renaming code. Hoping for something a little easier. – Sabor James Jan 31 '23 at 17:16

0 Answers0