daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set.seed(1)
  2. df <- data.frame( year = c(seq(2000, 2018), seq(2000, 2018)) , id = c(rep(1, 19),rep(2, 19)), varA = floor(rnorm(38)*100), varB= floor(rnorm(38)*100), varC= floor(rnorm(38)*100))
  3.  
  4. df <- df %>% mutate(varA = if_else(year>2010, as.double(NA) , varA) ,
  5.                     varB = if_else(year>2010, as.double(NA) , varB),
  6.                     varC = if_else(year>2010, as.double(NA) , varC))  %>% group_by(id) %>% arrange(year)
  7.    
  8. df <- df %>% mutate( varD = lag(varA)*lag(varB),
  9.                      varRESULT = if_else(is.na(varC), lag(varC, 1)/lag(varD, 2)*lag(varD, 1), varC))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top