-1

Let's say I have a data frame with values from column 1-11. For columns 1-10, I want to subtract column 11. Basically I want dataframe[1]-dataframe[11], dataframe[2]-dataframe[11], dataframe[3]-dataframe[11], dataframe[n] - dataframe[11], etc...

So basically, in VBA terms, it would be like:

For each column in dataframe, starting with column 1, subtract column 11 from it.

How do I do that?

Thanks!

confused
  • 194
  • 1
  • 13

1 Answers1

0

You can just do the subtraction directly.

df[,1:10] = df[,1:10] - df[,11]
G5W
  • 36,531
  • 10
  • 47
  • 80