Guest User

Untitled

a guest
Nov 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. ID V value weight
  2. A 1 8723.286 0.12183436
  3. A 0 8889.905 0.09787817
  4. A 1 14984.370 1.00000000
  5. B 1 8176.189 0.12183436
  6. B 1 8342.808 0.09787817
  7. B 1 14437.272 0.18412047
  8.  
  9. ID V value weight output
  10. A 1 8723.286 0.12183436 8869.605081
  11. A 0 8889.905 0.09787817 8869.605081
  12. A 1 14984.37 1.00000000 8869.605081
  13. B 1 8176.189 0.12183436 10998.48252
  14. B 1 8342.808 0.09787817 10998.48252
  15. B 1 14437.272 0.18412047 10998.48252
  16.  
  17. dat <- data.frame(
  18. ID = rep(c("A","B"), each=3),
  19. V = c(1,0,1,1,1,1) ,
  20. value = c(8723.286, 8889.905, 14984.37, 8176.189, 8342.808, 14437.272),
  21. weight = c(0.12183436, 0.09787817, 1.00000000, 0.12183436, 0.09787817, 0.18412047)
  22. )
  23.  
  24. dats <- split(dat, dat$ID)
  25.  
  26. ifelse(dats[[1]]$V[1]==1 & dats[[1]]$V[2]==0, dats[[1]]$weight[1]*dats[[1]]$value[1]+(1-dats[[1]]$weight[1])*dats[[1]]$value[2], NA)
  27.  
  28. ifelse(dats[[2]]$V[1]==1 & dats[[2]]$V[2]==1, dats[[2]]$weight[1]*dats[[2]]$value[1]+(1-dats[[2]]$weight[1])*((dats[[2]]$value[2]+dats[[2]]$value[3])/2), NA)
Add Comment
Please, Sign In to add comment