0

I am having a dataset name noaaFilename which is having multiple columns, out of those columns I need to change name of 3 columns (Dat, HrMn, Slp) to (Date, Time, AtmosPressure) and then make a data frame of these 3 columns. I am trying to do this, but unable to get result with column values.

colnames(noaaFilename)

  names(noaaFilename)[names(noaaFilename) == "Date"] <- "Date"
  names(noaaFilename)[names(noaaFilename) == "HrMn"] <- "Time"
  names(noaaFilename)[names(noaaFilename) == "Slp"] <- "AtmosPressure"

  noaaData <- data.frame("Date", "Time", "AtmosPressure")
  • If the existing column name is "Dat" then you need to make your indexing test `names(noaaFilename) == "Dat"` – IRTFM Feb 16 '20 at 02:45
  • 1
    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 Feb 16 '20 at 02:45
  • @MrFlick - Kindly help me with this, I have made a fresh link for this problem. https://stackoverflow.com/questions/60248600/renaming-sub-column-names-and-then-creating-a-data-frame-using-renamed-column-in – Shashank Shekhar Feb 16 '20 at 12:51

1 Answers1

0

After changing the names you need to subset columns from the dataframe

noaaData <- noaaFilename[c('Date', 'Time', 'AtmosPressure')]
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • 1
    When I am trying to do that then I am getting in all columns, can you please write the complete code? – Shashank Shekhar Feb 16 '20 at 02:39
  • 2
    @ShashankShekhar There's no way to "write the complete code" if you have not provided complete data descrtiption. Use SO [edit] facilities to put the results of `str(noaaFilename)` in your question body. – IRTFM Feb 16 '20 at 02:47
  • @42 - Here is the fresh link for this problem: https://stackoverflow.com/questions/60248600/renaming-sub-column-names-and-then-creating-a-data-frame-using-renamed-column-in – Shashank Shekhar Feb 16 '20 at 12:50
  • You shoud not do that. You should respond to questions by editing your question. I have flagged this question for deletion, but please read "How to Post". – IRTFM Feb 16 '20 at 17:18