I have a table in R with the following structure:
ID var1 var2 var3 .... varN
AA 1 2 1 3
AB 0.2 1 4 1
…
How can I select only those rows where var1<2 and var2<2 and var3<2 and … varN<2 ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your dataframe is
datthe test for all elements in a row being less than 2 and retruning only those rows would be:The logic: the inner apply returns a logical matrix:
Notice that it is transposed in dimensions, since R matrices are constructed column-major order, so the outer apply needs to work on columns, hence the use of 2 as the INDEX for applying the
allfunction. Testing: