I am looking for a function through which i can extract the last N digits from a Variable and save them in a New Variable in the same dataset. The dataset which i have is in the data.table format. I have around thousand of variables in my data frame so listing the data for some of them:
CaseID Var1 Var2 Var3
298710 1 1 2
399761 3 1 1
200987 1 5 3
Now, the function which i am looking for is something in which i can enter the number of digits to extract from CaseID variable and it will create a new variable as shown below:
CaseID Var1 Var2 Var3 Newvar
298710 1 1 2 0
399761 3 1 1 1
200987 1 5 3 7
Please note in my data, the class of CaseID is of Character type.
if you could help me out here then it would be really helpful.
Thanks in advance.