1

I have a column with anomaly values and I want to weight it with a specific number representing the number of years (32).

How can I do this?

data(mtcars)
mtcars$weight<-apply(mtcars[5], 1, ??, 32)
foo
  • 33
  • 6

1 Answers1

1
mtcars$weighted <- mtcars$drat * 32

Or if your weights are different for each observation

mtcars$weighted <- mtcars$drat * mtcars$cyl

No need for apply, multiplication is already vectorized for your convenience ;)

dario
  • 6,415
  • 2
  • 12
  • 26