How Do I Change Column Content Based On Previous Row?
Apologies. Whenever I try to make them into tables rather than into code it seems to think I have a code embedded and won't let me post this. So here's an example of What I have H
Solution 1:
Edit Thanks to r2evans now without rowwise()
.
Perhaps this is what you are looking for:
library(dplyr)
library(tidyr)
df %>%
mutate(Begin_New = Map(seq, Begin, End -6000,list(by =1000)))%>%
unnest(Begin_New)%>%
group_by(ID, File, Period)%>%
mutate(End_New = ifelse(Begin_New +7000> End, End, Begin_New +6000))
returns
# A tibble: 428 x 10
ID File Period Begin End Laser1 Laser2 Lead Begin_New End_New
<chr><chr><chr><dbl><dbl><chr><chr><chr><dbl><dbl>1 A01 longname.zip Baseline 030500 qfin plethh plethi 060002 A01 longname.zip Baseline 030500 qfin plethh plethi 100070003 A01 longname.zip Baseline 030500 qfin plethh plethi 200080004 A01 longname.zip Baseline 030500 qfin plethh plethi 300090005 A01 longname.zip Baseline 030500 qfin plethh plethi 4000100006 A01 longname.zip Baseline 030500 qfin plethh plethi 5000110007 A01 longname.zip Baseline 030500 qfin plethh plethi 6000120008 A01 longname.zip Baseline 030500 qfin plethh plethi 7000130009 A01 longname.zip Baseline 030500 qfin plethh plethi 80001400010 A01 longname.zip Baseline 030500 qfin plethh plethi 90001500011 A01 longname.zip Baseline 030500 qfin plethh plethi 100001600012 A01 longname.zip Baseline 030500 qfin plethh plethi 110001700013 A01 longname.zip Baseline 030500 qfin plethh plethi 120001800014 A01 longname.zip Baseline 030500 qfin plethh plethi 130001900015 A01 longname.zip Baseline 030500 qfin plethh plethi 140002000016 A01 longname.zip Baseline 030500 qfin plethh plethi 150002100017 A01 longname.zip Baseline 030500 qfin plethh plethi 160002200018 A01 longname.zip Baseline 030500 qfin plethh plethi 170002300019 A01 longname.zip Baseline 030500 qfin plethh plethi 180002400020 A01 longname.zip Baseline 030500 qfin plethh plethi 190002500021 A01 longname.zip Baseline 030500 qfin plethh plethi 200002600022 A01 longname.zip Baseline 030500 qfin plethh plethi 210002700023 A01 longname.zip Baseline 030500 qfin plethh plethi 220002800024 A01 longname.zip Baseline 030500 qfin plethh plethi 230002900025 A01 longname.zip Baseline 030500 qfin plethh plethi 240003050026 A01 longname.zip Run 3050068500 qfin plethh plethi 305003650027 A01 longname.zip Run 3050068500 qfin plethh plethi 315003750028 A01 longname.zip Run 3050068500 qfin plethh plethi 325003850029 A01 longname.zip Run 3050068500 qfin plethh plethi 335003950030 A01 longname.zip Run 3050068500 qfin plethh plethi 3450040500
I named the columns Begin_New
and End_New
, you could change that easily into Begin
and End
.
Post a Comment for "How Do I Change Column Content Based On Previous Row?"