0

The ms.compute function in the RxnSim package requires me to specify two variables I want to compare. I am not sure how I can define the variables (i.e. ms.compute(x,y)) in the ms.compute function so that the function uses whatever is in the columns in the current row, and make the function repeat for each row, and ideally output the result in a third column.

      df
      X1 X2
    1  1  6
    2  2  7
    3  3  8
    4  4  9
    5  5 10

For this df, I would want a third column X3 to return the result of a function like: FUN(x+y), in which x,y are 1,6 for row 1 etc. and have this function repeat for each row, so row 1 = 7, row 2 = 9 etc.

pklemmer
  • 1
  • 2
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 13 '22 at 17:42
  • `df$X3 <- df$X1 + df$X2` – jpdugo17 Apr 15 '22 at 04:11

1 Answers1

1

Using dplyr might be easier

df <- df%>%
mutate(sum = x1+x2)
ale_ish
  • 159
  • 7