Suppose I have a list:
alist<- list(4,6,8,9)
I want test if each list element is greater than 7 and return a list of 1 if its true and 0 if false.
However I must use lapply.
lapply(alist,if,>7,1) or lapply(alist,if,cond>7,1)
Of course none of these work and I keep getting the following error.
Error: unexpected ',' in "lapply(alist, if,"
It pains me to answer this because it’s very un R to do this. You could try being more explicit and use brackets as in:
Or the vectorized
ifelseOr best of all: