how to generate a new variable in this case?

data.frame(
         bill = c(1L,1L,2L,2L,3L,3L,4L,4L,5L,5L,
                  6L,6L,7L,7L,8L,8L,9L,9L,10L,10L,11L,11L,12L,12L),
        treat = c(0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,
                  0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,0L,1L,0L,1L),
  monthenergy = c(36.7032538284079,46.0402438841829,
                  32.9392795881018,41.2984949950169,28.1280279158878,
                  35.480098154243,24.9235110867169,31.8601494904683,25.8690610384381,
                  33.4558628130817,29.2486150406169,38.301071827994,
                  37.3012423685873,49.7570793648139,37.1106026686834,49.1615012450902,
                  38.0010307369504,50.4640419568872,25.6031441545062,
                  33.6860808231507,25.4171150782655,32.6026074847544,31.1551553278784,
                  39.2106574963103)
)

I need to generate a new variable, that is the difference between the treat=1 and treat=0 for each bill.

See dplyr::mutate for that

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

can you give me the code?

At this point, I'm going to have to point you to the dplyr documentation

Winston Churchill, before he became a politician, participated in the last cavalry charge of the British Army, in the Battle of Omdurman. In his book, The River War, he relates the thrilling (to him, at least) 30-minute battle, but emphasizes that it was preceded by a months-long construction of a railroad to bring the force of the British to bear.

Preparation pays. Take the time to understand the tools, and you will be able to build better results more quickly.

1 Like