My data has the following format: - first column: indication if the machine is running - second column: Coordinate to indicate the distance that the machine is running
See here below the dataset:
structure(c("", "", "running", "running", "running", "running",
"running", "running", "running", "", "504", "678", "268", "475",
"675", "796", "745", "693", "665", "488"), .Dim = c(10L, 2L), .Dimnames = list(
NULL, c("e", "f")))
I would like to add a third column that gives the total distance that the machine has been running (by adding all the absolute differences since the machine started to run). See here below the desired output:
e f Output
[1,] "" "504" ""
[2,] "" "678" ""
[3,] "running" "268" "0"
[4,] "running" "475" "207"
[5,] "running" "675" "407"
[6,] "running" "796" "528"
[7,] "running" "745" "579"
[8,] "running" "693" "631"
[9,] "running" "665" "659"
[10,] "" "488" ""
I tried to write some code in R to get this in an elegant way, but my programming skills are too limited for the moment. Is there anybody that knows a solution for this problem? Thank you on beforehand!
Aucun commentaire:
Enregistrer un commentaire