Good morning all,
I am new to R and have searched long enough for an answer to a fairly basic problem ...
I have a dataset with various variables. My columns 6 to 50 are particle volumes and I would just like to have a new column (hence a new variable) that is the sum of all the other columns:
For example: imagine that I have 4 columns A B C and D:
A B C D
0 1 1 2
I would then like to have a column E which for this row indicates 4
Thanks a lot for your answer !
I don't understand what your 1:20 is and the ncol = 4?
I was thinking of using the mutate function to create a new variable which would be the sum of my columns.
Basically I have a basic data set called dataset1 with my variables 6 to 50 were volumes according to particle sizes, each variable has the mention LPM in its name. I just want to add all the volumes of each of the sizes to have only one variable and not 44
mat1 <- matrix(1:20, ncol = 4)
This just creates a matrix as sample data. I created a matrix of the numbers from 1 to 20 arranged in 4 rows. The ncol specifies the number of rows.
.
I do not usually use tidyverse so I don"t know if mutate() is the correct approach. My approach is simple basic R which will do the job. Note, if you have NAs in the data you will need to use
Hello !
I was finally able to find out how to do it! I used mutate, thank you very much for your help, I was able to learn a lot about the different ways of using R:
if you are interested, here is how I proceeded: