Vishnu Raghavan
Vishnu Raghavan

Reputation: 83

Scaling data subsetwise using R

I Have the following dataset regarding a digital marketing problem. the size of the audience, no of inactive e mails read mails and the priority of the segment are given

 AudienceSize   inactiveemails  Readmails   Importanceof targetgroup
   246238       63581          1015         Low
    402042       609           2089         Medium
      2395        4              12         Medium
      10958       76             105        High
     120291     1237             707        Medium
      65199      0               544        Low
      106341    1506             1171       Medium
      496986    8501             3139      Medium
     293509     4805            2059        Medium
       93218     97              814       Medium
     246238     63581           1015          Low
      402042     609            2089        Medium
      2395        4              12         Medium
      10958       76             105        High
      120291    1237             707        Medium
      65199      0               544        Low
      106341    1506             1171      Medium
      496986    8501             3139      Medium
      293509    4805            2059       Medium
      93218     97               814       Medium

I need to scale the data. The low priority e mails should be scaled among members low category alone. Similarly for the medium and high category, the scaling should be done using that alone. Is there anyway to achieve this.

Importanceoftargetgroup  AudienceSize Readmails Inactivemails
Low                          .03444     .5366     .7437
Low                          .03664     .7500     .8000
medium                        .7665      .4333    .6543
medium                        .7965      .5533    .7543

Note: DPLYR has helped me subset the data and get means, but I need the scaled versions.

Upvotes: 1

Views: 214

Answers (1)

Prem
Prem

Reputation: 11955

You should get the desired result using

library(dplyr)
df %>%
  group_by(Importanceoftargetgroup) %>%
  mutate_each(funs(scale), AudienceSize, inactiveemails, Readmails)

Upvotes: 3

Related Questions