I have a data frame called data. I want to create a function f (data, collist). This function takes data and a list of columns from the data itself and returns only those rows from the data for which the mentioned column names in collist are not NA. I know that this can be done using for loop, but I want to do this without using for loop.
Also, please let me know if in R it is generally more efficient to avoid loops.
Here is an example:
ABCD 1 2 NA NA 2 NA NA NA NA 3 7 5 NA 4 2 NA 5 6 NA NA
If the collist contains B and C, then a reduced data frame with row number 1,3,4 will be returned. The reason is either B or C, or both have NA in lines 2 and 5. I need a function because I will use this operation quite a few times. On this subject, I will learn some new R tricks, as well as make my program more elegant. Thanks.
Sumit source share