subset - Boolean operators and which() function in R -


I have a data frame, and I want to subscribe by selecting all the rows that correspond to a condition on the factor < Value for Code> Year :

  subset_df < - df [(which (df $ year <1972) || (df $ year> '1982')),]   

My problem is that Returns the whole dataframe, df from the above line.

Forgive me if this is very basic or simple, but I do not know where the fault is.

I suspect that || is something I do not understand, or my second theory is that arr.ind = T plays a role either, or The nature of () function is slightly more complex because I think it is.

If someone has any insights, I would appreciate it very much. Thanks for your time.

PS: Yes, it works as expected and gives the right subset; That is, there is no flaw in my dataframe:

  test_df & lt; - df [(which (df $ year <1972 ')),]   

As it is equivalent to 1982

Note that you can read from the helpfile (see ? "|" ):

for |, & amp; And for a logical or raw vector xor ... and ... for ||, & amp; Amp; And ITRU, a length-a logical vector.

So you have your || to can change and I think that

  subset_df    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -