Thanks so much @andresrcs! That link was super helpful. I'm hoping I did the reprex correctly.
This is the input dataset:
dataset <- data.frame(stringsAsFactors=FALSE,
Veto_name = c("success", "success", "success", "veto1", "veto1", "vetox",
"veto2", "veto2", "veto2", "veto3", "veto4", "veto4", "veto4",
"veto5"),
Stage = c(0L, 0L, 0L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L),
Count = c(1000L, 567L, 678L, 50L, 21L, 100L, 34L, 23L, 19L, 6L, 7L, 8L,
5L, 11L),
Machine = c("Win32", "Win32", "Mac", "Win32", "Win33", "Win34", "Win35",
"Win36", "Mac", "Win32", "Win32", "Mac", "Win32", "Win32"),
Color = c("Green", "Blue", "Orange", "Green", "Blue", "Green", "Green",
"Blue", "Orange", "Green", "Blue", "Orange", "Green",
"Green")
)
This is with the additional column Count_Prev_Stage that I'm trying to calculate (here I just typed in values to the spreadsheet). I'd like to figure out how to calculate this column using R.
result_with_count_prev_stage_col <- data.frame(stringsAsFactors=FALSE,
Veto_name = c("success", "success", "success", "veto1", "veto1",
"vetox",
"veto2", "veto2",
"veto2",
"veto3", "veto4",
"veto4", "veto4",
"veto5"),
Stage = c(0L, 0L, 0L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L),
Count = c(1000L, 567L, 678L, 50L, 21L, 100L, 34L, 23L, 19L, 6L,
7L, 8L, 5L,
11L),
Machine = c("Win32", "Win32", "Mac", "Win32", "Win33", "Win34",
"Win35",
"Win36", "Mac",
"Win32", "Win32",
"Mac", "Win32",
"Win32"),
Color = c("Green", "Blue", "Orange", "Green", "Blue", "Green",
"Green",
"Blue", "Orange",
"Green", "Blue",
"Orange",
"Green", "Green"),
Count_Prev_Stage = c("null", "null", "null", "1000", "567", "1000", "850",
"546", "678",
"850", "546",
"675", "810",
"810")
)