R突变列查询

时间:2019-04-12 23:31:39

标签: r

我陷入了一个有趣的问题。

我有这个数据集

CARD_NO(char),Name(char), Amount(integer), Date(Date)   
6323246954,Ramon Lopez,62472.07,2019-01-02
7021289247,Bruce Yael,26245.30,2018-12-14
8311285536,Daisy Pascal,42377.31,2018-12-23
8541521746,Amy Chris,107978,2018-12-19

对于数据集的每一行,我必须添加一个新列,该列应为长度为10的字符串。 生成字符串的规则如下

V1 : ="S" if amount is >50000 else "F"
V2,V4,V6,V8,V10 : Reverse of (99999-first five digits of the CARD_NO.)

eg. for second row CARD_NO = 7021289247
First 5 digits= 70212
99999-70212= 29787
Reverse(29787) : 78792
therefore V2 =7
V4=8
V6=7
V8=9
V10:=2


now to calculate other
V3: If First letter of First name is at Nth position in alphabetical order, find alphabet in Nth position of reverse alphabetical order. 
V5: If First letter of Last name is at Nth position in alphabetical order, find alphabet in Nth position of reverse alphabetical order.
V7: single digit sum of Amount 
V9: single digit sum of Date 


eg: 2nd row 
7021289247,Bruce Yael,26245.30,2018-12-14
V3 = "Y" as firstname_firstchar="B" i.e at index 2 therefore Y (index 2 from reverse side)
V5="B" as lastname_firstchar="Y" i.e at index 25 therefore B (index 25 from reverse side)
V7=4 as amount =26245.30 
therefore 2+6+2+4+5+3+0 =22 -> 2+2 =4

V9=1 as date = 2018-12-14
2+0+1+8+1+2+1+4 =19 -> 1+9=10 -> 1+0 =1

also V1="F" as amount is Less than 50000

所以终于  for 7021289247,Bruce Yael,26245.30,2018-12-14

生成的字符串为 F7Y8B74912

请帮助我编写一个R代码,根据这些规则为所有行创建此新列

0 个答案:

没有答案