7
i am a beginner in the R language and wanted to know how I create a function mutate that creates a new column in my table and at the same time store in this new column the sum of the values contained in the other 6 columns of my table as in the example below, also wanted to create another column called Ratio on the side of the Total Soma_column that would take the largest number present between columns A and F and divide it by the value contained in the Total Soma_column. For example, in the first row of the ratio column I would have 100 (higher value between columns A and F)/150 (value contained in the Total Soma_column).
Important details: the columns of A: F are of the Character type and I have a series of NA’s in these columns that I would like to disregard when making my sum.
A B C D E F Soma_total Proporcao
100 50 NA NA NA NA 150 (100/150)
49 51 1 NA NA NA 101 (51/101)
30 20 5 1 NA NA 56 (30/56)
11 10 2 NA NA NA 23 (11/23)
7 3 5 1 1 1 18 (7/18)
0 10 NA NA NA NA 10 (10/10)
1 2 NA NA NA NA 3 (2/3)
5 6 2 NA NA NA 13 (6/13)
7 3 1 3 1 NA 15 (7/15)
12 3 1 2 NA NA 18 (12/18)
All you need to do is pack the proportion numerator, swapping the A for the maximum between A and F! abs
– Athos
It’s true, @Athos. I didn’t really read the question! Thanks for your answer, I learned about Pmax(), and rowSums()
– Dan