pkpkPPkafa pkpkPPkafa - 1 year ago 91
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.



Answer Source

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

Data[, -(1:4)] <- Data[,-(1:4)]/(10^6)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download