Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID V value weight
- A 1 8723.286 0.12183436
- A 0 8889.905 0.09787817
- A 1 14984.370 1.00000000
- B 1 8176.189 0.12183436
- B 1 8342.808 0.09787817
- B 1 14437.272 0.18412047
- ID V value weight output
- A 1 8723.286 0.12183436 8869.605081
- A 0 8889.905 0.09787817 8869.605081
- A 1 14984.37 1.00000000 8869.605081
- B 1 8176.189 0.12183436 10998.48252
- B 1 8342.808 0.09787817 10998.48252
- B 1 14437.272 0.18412047 10998.48252
- dat <- data.frame(
- ID = rep(c("A","B"), each=3),
- V = c(1,0,1,1,1,1) ,
- value = c(8723.286, 8889.905, 14984.37, 8176.189, 8342.808, 14437.272),
- weight = c(0.12183436, 0.09787817, 1.00000000, 0.12183436, 0.09787817, 0.18412047)
- )
- dats <- split(dat, dat$ID)
- 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)
- 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