-1

I have a column of 5 digit code values (from 1-3) values in R with 243 possible combinations (5 digits, each digit can be 1, 2, or 3):

Example:

13212

13211

However, each 5 digit code represents a coresponding value.

For instance:

13212 = 0.5120

13211 = 0.1232

How do I imput the unique corresponding value for each of these 243 numeric codes?

How do I tell R to convert my column of numeric codes into their coresponding values?

GSee
  • 48,880
  • 13
  • 125
  • 145
Mark
  • 91
  • 1
  • 1
  • 8
  • Something like this? http://stackoverflow.com/questions/3905038/replace-values-in-a-vector-based-on-another-vector – Roman Luštrik Apr 22 '13 at 13:45
  • Hi Roman, I want R to give me a new column with the new value? – Mark Apr 22 '13 at 13:54
  • is there any mathematical relation that makes `13212 = 0.5120` and `13211 = 0.1232` ? – Michele Apr 22 '13 at 14:00
  • Assigning result values to a new column is trivial (e.g. my.data$new.data <- my.result`. The "tricky" part is to convert from your factor (or whatever your coding is) to that numeric. Have you tried the solutions in the link I pasted? – Roman Luštrik Apr 22 '13 at 14:12
  • Michele, no mathematical relation, each 5 digit code has a corresponding value that I have from a scoring manual. – Mark Apr 22 '13 at 14:18
  • Since you seem to need to input these scores by hand anyway (be your manual pape or digital), make a CSV file and then import it into R using `read.csv`. You can use e.g. Excel to create CSV files. – Maxim.K Apr 22 '13 at 19:04
  • http://stackoverflow.com/questions/14232899/replacing-values-in-one-column-with-another-based-on-a-3rd-column-matching-a-4th?rq=1 Credit to Sven Hohenstein for this answer. – Mark Apr 23 '13 at 13:28

1 Answers1

0

Probably not the best solution, but if you want to replace every value1 of a vector with value2:

relations=data.frame(value1=c(13212,13211),value2=c(0.5120,0.1232))
values=c(13212,13211)
for (i in 1:length(values)){
   values[i]=relations$value2[relations$value1==values[i]]
}
Jessica B
  • 321
  • 1
  • 4
  • 15