pkpkPPkafa pkpkPPkafa - 8 months ago 40
R Question

Arithmetic on multiple columns/rows of dataframe in R

I have dataset with a header (of years) and four columns that designate different characteristica

For each year, I want to divide all observations by 10^6, except for the first four columns. I know one can do


if one wants the first column to be left out, but what about if one needs four.




We can use the sequence of 1:4, wrap it inside (..) and use the -.

Data[, -(1:4)] <- Data[,-(1:4)]/(10^6)