r - Apply a calculation over every column -


i have dataset 67 columns. each column has heterogeneous names "flower", "stones", "xxxx", "yyyy", etc.

i want following: iterate 2nd through 67th column , replace value of each column sum of original value , corresponding value in first column.

as small example, suppose dataset contains 3 columns following values:

         first colum     flowers       stones         3                   2           2          4                   5           3         5                   6           1         6                   7           9 

after applying desired step, should this:

         first colum     flowers      stones          3                   5           5          4                   9           7         5                   11          6         6                   13          15 

if dat dataset

 dat[,-1] <- lapply(dat[,-1], function(x) x+dat[,1])   dat   #  first colum flowers stones   #1           3       5      5   #2           4       9      7   #3           5      11      6   #4           6      13     15 

or

 dat[,-1] <- dat[,-1]+dat[,1] 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -