I have the following piece of code:
TB <- data.frame(1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9)
TB$BIG_value <- apply(TB,1,function(r){
sr <- sort(r[9:14],decreasing = TRUE)
value <- sr[1] - 0.5*sr[3] - 0.25*sr[4] - 0.125*sr[5] - 0.0625*sr[6]
defaltv <- data.frame(c(1))
if((value==0)[1,1]{
defaltv
}else{
value
}
})
It's aim is to create a new column in TB, the value of which is either a function of columns 9:14 or 1, if the function returns 0.
If I run the code outside of the apply it works, however when inside it returns several errors saying Error: 'unexpected '}' in " }"'.
Thanks