Hello,
I am trying to perform addition and subtraction on same column
So I got the column with name total and it has values
1
2
3
4
5
I need to get a<- 1+2+3 = 6
B<- 4+5 =9
C = b-a = 3
How can I write code for this ?
Please help me
Thank you
I would love to help you, but I don't understand what you are asking for help with it all.
Hi,
I agree with @nirgrahamuk . In order for us to help you with your question, please provide us a minimal reproducible example where you provide a minimal (dummy) dataset and code that can recreate the issue. Once we have that, we can go from there. For help on creating a Reprex, see this guide:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
Good luck!
PJ
What the guys said above holds, but you can accomplish what you want with the following code.
data <- data.frame(Total = seq(1,5,1))
a <- sum(data[1:3,])
b <- sum(data[4:5,])
c <- b - a
system
Closed
March 4, 2022, 1:10pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.