n*********e 发帖数: 318 | 1 I am trying to translate prod id into prod name
Here is data -
#----------------------
customer_id, product_id, date
11111,634578,11/12/2011
11111,987654,11/12/2011
11111,678978,11/12/2011
11111,678978,12/22/2011
22222,456789,12/24/2011
33333,678978,01/10/2012
33333,678978,01/15/2012
44444,987365,03/30/2012
I also has a reference file -
prod_id, prod_name
634578, 'ice-cream'
987654, 'green beans'
678978, 'beef'
...
------------------------------------------------------------
How can I do it in R so that my data will have an additional column 'prod_
name'?
Thanks. | t*****i 发帖数: 426 | | n*********e 发帖数: 318 | 3 what is the thing in R which would be equivalent to -
'map' in Java
'dictionary' in Python
'PROC FORMAT' in SAS
? | t******g 发帖数: 372 | 4 datanew<-cbind(data, as.character(ref[match(data[, 'prod_id'], ref[,'prod_id
']),'prod_name']))
【在 n*********e 的大作中提到】 : I am trying to translate prod id into prod name : Here is data - : #---------------------- : customer_id, product_id, date : 11111,634578,11/12/2011 : 11111,987654,11/12/2011 : 11111,678978,11/12/2011 : 11111,678978,12/22/2011 : 22222,456789,12/24/2011 : 33333,678978,01/10/2012
| s*r 发帖数: 2757 | 5 R vector can have names
w <- 1:3
names(w) <- c('s','i','r')
w['i']
【在 n*********e 的大作中提到】 : what is the thing in R which would be equivalent to - : 'map' in Java : 'dictionary' in Python : 'PROC FORMAT' in SAS : ?
|
|