0

Thank you for anyone's advice and help! I am trying to use R to replace one column's values with the values of another column correspondent to its specific id.

For example, in the short snippet below I am trying to convert the nearestN column of values to instead display the Sscore for that nearestN's OBJECTID.

I other words, is there a code I can run that transforms the "8" in the nearestN column to a "10.050505," the "27" to a 14.260462," etc.?

OBJECTID    NAME            Sscore  nearestN
2           Abbeville city  10.826118   8
8           Alexander City  10.050505   27
10          Aliceville city 3.030303    15
15          Anniston city   5.8333335   10
27          Auburn city     14.260462   2
lmo
  • 37,904
  • 9
  • 56
  • 69
TXE
  • 1
  • 2
    This is question has been asked many times before. You can use `match`. In this instance, `dat$Sscore[match(dat$nearestN, dat$OBJECTID)]`. – lmo Oct 24 '17 at 18:26
  • 1
    Possible duplicate of [How do I replace NA values with zeros in an R dataframe?](https://stackoverflow.com/questions/8161836/how-do-i-replace-na-values-with-zeros-in-an-r-dataframe) – SherylHohman Oct 24 '17 at 18:37
  • Almost, but after watching this video: https://www.youtube.com/watch?v=vJaEE_kHhCw I realized I actually was hoping to create a new vector with these matched values. Therefore what ended up working for me was to create a new df called NearOne, enter a new integer vector "sccore" and then match it with the prior df as such: NearOne$sscore = dat$sscore[match(NearOne$nearestN, dat$OBJECTID)] – TXE Oct 28 '17 at 18:29

0 Answers0