dimanche 26 janvier 2020

Trying to put if condion in r and creating a new variable with certain condition on two variables

Group A      Group B
custid       sd,custid,region-101%41,townsize
region       region
townsize     townsize
gender       gender,(part2)
age          agecat,birthmonth,gendor
agecat       birthmonth
birthmonth   edcat

The SQL:

Select *,
       case when (GroupA=GROUPB) "OK"
            WHEN INSTR(GROUPA,GROUPB,1,1)>0 
                 and INSTR(GROUPA,GROUPB,',',1,1)>0"Ok but different groups"
       ELSE Review group "review);

The above code is working fine when trying to import data from oracle database.

I want to use same condition on r after creating a dataset in r language but it is not working,I tried sqldf package but still it is not working

Group A      Group B
custid       sd,custid,region-101%41,townsize
region       region
townsize     townsize
gender       gender,(part2)
age          agecat,birthmonth,gendor
agecat       birthmonth
birthmonth   edcat

enter image description here

If you could please help to write this query in R or sql .

Aucun commentaire:

Enregistrer un commentaire