df <- trt %>% arrange(DoseAmount) %>% groupby(DoseAmount) %>% mutate( group = cumsum(…
Jump to turn (8)
- 1df % arrange(DoseAmount) %>% groupby(DoseAmount) %>% mutate( group = cumsum( Dos
- 2add logic to get the unique DoseAmount firstly then get group
- 3lag() in R get which record
- 4trtpn DoseAmount Notrt 1 5 2 1 10 1 2 10 2 3 100 2 4 500 2 for this data how to
- 5amt=c(rep(100,4), rep(50,16)) how to achieve it by loop, how many rep exist in t
- 6trtpn DoseAmount Notrt 1 5 2 1 10 1 2 10 2 3 100 2 4 500 2 this data how to use
- 7DoseAmount 300 300 100 how to keep this variable's value's order and generate a
- 8intervals <- c() # initialize an empty vector to store the intervals for (i in 1
- User
df <- trt %>% arrange(Dose_Amount) %>% group_by(Dose_Amount) %>% mutate( group = cumsum( Dose_Amount != lag(Dose_Amount, default = first(Dose_Amount))) ) %>% ungroup() how to fix this code when Dose_Amount's value changed then group will be group+1
if dose <- (5,5,10,10,15,15,20) then
- Assistant
You can modify the code by adding an additional condition in the
mutatestatement to increment the group value by 1 whenever the Dose_Amount value changes. Here's the modified code:Rdf <- trt %>% arrange(Dose_Amount) %>% group_by(Dose_Amount) %>% mutate( group = cumsum( Dose_Amount != lag(Dose_Amount, default = first(Dose_Amount)) | row_number() == 1 # add this condition to increment group on first row ) ) %>% ungroup()