Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divide every number in every column by 1000 in R

Tags:

r

I would like to divide every number in all columns by 1000. I would like to omit the row header and the 1st column from this function.

I have tried this code:

 TEST2=(TEST[2:503,]/(1000))

But it is not what I am looking for. My dataframe has 503 columns.

like image 845
user1977802 Avatar asked Mar 18 '14 07:03

user1977802


1 Answers

Is TEST a dataframe? In that case, the row header won't be divided by 1000. To choose all columns except the first, use an index in j to select all columns but the first? e.g.

TEST[, 2:ncol(TEST)]/1000 # selects every row and 2nd to last columns
# same thing
TEST[, -1]/1000 # selects every row and every but the 1st column

Or you can select columns by name, etc (you select columns just like how you are selecting rows at the moment).

Probably take a look at ?'[' to learn how to select particular rows and columns.

like image 64
mathematical.coffee Avatar answered Sep 21 '22 00:09

mathematical.coffee