Skip to main content
deleted 5 characters in body
Source Link

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

   cz    btype       year   midfs    value      midfs1
1    College     2014   5.4254  0.007582767 5.4254
1    College     2015   5.4779  0.007582767 NA
1    College     2016   5.5191  0.007582767 NA
1    College     2017   5.5616  0.007582767 NA
1    College     2018   5.6097  0.007582767 NA
1    Grocery     2012   4.8267  0.002697526 NA
1    Grocery     2013   4.8205  0.002697526 NA
1    Grocery     2014   4.8583  0.002697526 4.8583
1    Grocery     2015   4.8966  0.002697526 NA
1    Grocery     2016   4.9556  0.002697526 NA
1    Grocery     2017   5.0258  0.002697526 NA
1    Grocery     2018   5.0982  0.002697526 NA
1    Grocery     2019   5.1514  0.002697526 NA
1    Grocery     2020   5.1976  0.002697526 NA
1    Grocery     2021   5.2338  0.002697526 NA

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

   cz    btype       year   midfs    value      midfs1
1    College     2014   5.4254  0.007582767 5.4254
1    College     2015   5.4779  0.007582767 NA
1    College     2016   5.5191  0.007582767 NA
1    College     2017   5.5616  0.007582767 NA
1    College     2018   5.6097  0.007582767 NA
1    Grocery     2012   4.8267  0.002697526 NA
1    Grocery     2013   4.8205  0.002697526 NA
1    Grocery     2014   4.8583  0.002697526 4.8583
1    Grocery     2015   4.8966  0.002697526 NA
1    Grocery     2016   4.9556  0.002697526 NA
1    Grocery     2017   5.0258  0.002697526 NA
1    Grocery     2018   5.0982  0.002697526 NA
1    Grocery     2019   5.1514  0.002697526 NA
1    Grocery     2020   5.1976  0.002697526 NA
1    Grocery     2021   5.2338  0.002697526 NA

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

   cz    btype       year   midfs    value      midfs1
1    College     2014   5.4254  0.007582767 5.4254
1    College     2015   5.4779  0.007582767 NA
1    College     2016   5.5191  0.007582767 NA
1    College     2017   5.5616  0.007582767 NA
1    College     2018   5.6097  0.007582767 NA
1    Grocery     2012   4.8267  0.002697526 NA
1    Grocery     2013   4.8205  0.002697526 NA
1    Grocery     2014   4.8583  0.002697526 4.8583
1    Grocery     2015   4.8966  0.002697526 NA
1    Grocery     2016   4.9556  0.002697526 NA
1    Grocery     2017   5.0258  0.002697526 NA
1    Grocery     2018   5.0982  0.002697526 NA
1    Grocery     2019   5.1514  0.002697526 NA
1    Grocery     2020   5.1976  0.002697526 NA
1    Grocery     2021   5.2338  0.002697526 NA
added 34 characters in body
Source Link

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

     cz    btype    year   year   midfs    value    value  midfs1
College    1    College     2014    5.4254  0.007582767 5.4254
College    1    College     2015    5.4779  0.007582767 NA
College    1    College     2016    5.5191  0.007582767 NA
College    1    College     2017    5.5616  0.007582767 NA
College    1    College     2018    5.6097  0.007582767 NA
Grocery    1    Grocery     2012    4.8267  0.002697526 NA
Grocery    1    Grocery     2013    4.8205  0.002697526 NA
Grocery    1    Grocery     2014    4.8583  0.002697526 4.8583
Grocery    1    Grocery     2015    4.8966  0.002697526 NA
Grocery    1    Grocery     2016    4.9556  0.002697526 NA
Grocery    1    Grocery     2017    5.0258  0.002697526 NA
Grocery    1    Grocery     2018    5.0982  0.002697526 NA
Grocery    1    Grocery     2019    5.1514  0.002697526 NA
1    Grocery     2020   5.1976  0.002697526 NA
1    Grocery   2020  2021   5.19762338  0.002697526 NA

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

     cz    btype    year     midfs        value midfs1
College             2014    5.4254  0.007582767 5.4254
College             2015    5.4779  0.007582767 NA
College             2016    5.5191  0.007582767 NA
College             2017    5.5616  0.007582767 NA
College             2018    5.6097  0.007582767 NA
Grocery             2012    4.8267  0.002697526 NA
Grocery             2013    4.8205  0.002697526 NA
Grocery             2014    4.8583  0.002697526 4.8583
Grocery             2015    4.8966  0.002697526 NA
Grocery             2016    4.9556  0.002697526 NA
Grocery             2017    5.0258  0.002697526 NA
Grocery             2018    5.0982  0.002697526 NA
Grocery             2019    5.1514  0.002697526 NA
Grocery             2020    5.1976  0.002697526 NA

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

   cz    btype       year   midfs    value      midfs1
1    College     2014   5.4254  0.007582767 5.4254
1    College     2015   5.4779  0.007582767 NA
1    College     2016   5.5191  0.007582767 NA
1    College     2017   5.5616  0.007582767 NA
1    College     2018   5.6097  0.007582767 NA
1    Grocery     2012   4.8267  0.002697526 NA
1    Grocery     2013   4.8205  0.002697526 NA
1    Grocery     2014   4.8583  0.002697526 4.8583
1    Grocery     2015   4.8966  0.002697526 NA
1    Grocery     2016   4.9556  0.002697526 NA
1    Grocery     2017   5.0258  0.002697526 NA
1    Grocery     2018   5.0982  0.002697526 NA
1    Grocery     2019   5.1514  0.002697526 NA
1    Grocery     2020   5.1976  0.002697526 NA
1    Grocery     2021   5.2338  0.002697526 NA
added 63 characters in body
Source Link
eipi10
  • 94.5k
  • 28
  • 220
  • 299

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

cz btype year midfs value midfs1 College 2014 5.4254 0.007582767 5.4254 College 2015 5.4779 0.007582767 NA College 2016 5.5191 0.007582767 NA College 2017 5.5616 0.007582767 NA College 2018 5.6097 0.007582767 NA Grocery 2012 4.8267 0.002697526 NA Grocery 2013 4.8205 0.002697526 NA Grocery 2014 4.8583 0.002697526 4.8583 Grocery 2015 4.8966 0.002697526 NA Grocery 2016 4.9556 0.002697526 NA Grocery 2017 5.0258 0.002697526 NA Grocery 2018 5.0982 0.002697526 NA Grocery 2019 5.1514 0.002697526 NA Grocery 2020 5.1976 0.002697526 NA

     cz    btype    year     midfs        value midfs1
College             2014    5.4254  0.007582767 5.4254
College             2015    5.4779  0.007582767 NA
College             2016    5.5191  0.007582767 NA
College             2017    5.5616  0.007582767 NA
College             2018    5.6097  0.007582767 NA
Grocery             2012    4.8267  0.002697526 NA
Grocery             2013    4.8205  0.002697526 NA
Grocery             2014    4.8583  0.002697526 4.8583
Grocery             2015    4.8966  0.002697526 NA
Grocery             2016    4.9556  0.002697526 NA
Grocery             2017    5.0258  0.002697526 NA
Grocery             2018    5.0982  0.002697526 NA
Grocery             2019    5.1514  0.002697526 NA
Grocery             2020    5.1976  0.002697526 NA

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

cz btype year midfs value midfs1 College 2014 5.4254 0.007582767 5.4254 College 2015 5.4779 0.007582767 NA College 2016 5.5191 0.007582767 NA College 2017 5.5616 0.007582767 NA College 2018 5.6097 0.007582767 NA Grocery 2012 4.8267 0.002697526 NA Grocery 2013 4.8205 0.002697526 NA Grocery 2014 4.8583 0.002697526 4.8583 Grocery 2015 4.8966 0.002697526 NA Grocery 2016 4.9556 0.002697526 NA Grocery 2017 5.0258 0.002697526 NA Grocery 2018 5.0982 0.002697526 NA Grocery 2019 5.1514 0.002697526 NA Grocery 2020 5.1976 0.002697526 NA

I am trying to process by group data using dplyr but it is not working. Any help would be appreciated. Below is a sample of the data. I want to retain the value for year 2014 and calculate rest of the values for midfs1 using the lag(midfs1) and value. Below is my attempt at the problem.

 t3 = t2 %>% 
 group_by(cz,btype,year) %>%
 mutate( midfs1 = ifelse(year == 2014,midfs1,
 lag(midfs1)*value+lag(midfs1)))

t2 data:

     cz    btype    year     midfs        value midfs1
College             2014    5.4254  0.007582767 5.4254
College             2015    5.4779  0.007582767 NA
College             2016    5.5191  0.007582767 NA
College             2017    5.5616  0.007582767 NA
College             2018    5.6097  0.007582767 NA
Grocery             2012    4.8267  0.002697526 NA
Grocery             2013    4.8205  0.002697526 NA
Grocery             2014    4.8583  0.002697526 4.8583
Grocery             2015    4.8966  0.002697526 NA
Grocery             2016    4.9556  0.002697526 NA
Grocery             2017    5.0258  0.002697526 NA
Grocery             2018    5.0982  0.002697526 NA
Grocery             2019    5.1514  0.002697526 NA
Grocery             2020    5.1976  0.002697526 NA
Source Link
Loading