Kurapati, Ravichandra (Ravichandra)
2008-Nov-10 05:05 UTC
[R] is there any way to apply mulitiple conditions in subset function
Hi All, Let say > df Session_Setup DCT FwdDataVols_bin counts 761 0 1 1 87162 762 0 1 2 11495 763 0 1 3 3986 764 0 1 4 1583 765 0 1 5 920 766 0 1 6 920 767 0 1 8 306 768 0 1 9 966 769 0 1 12 307 770 0 1 13 305 771 0 1 14 355 772 0 1 17 308 773 0 1 19 308 774 0 1 22 616 775 0 1 23 307 776 0 1 25 307 777 0 1 26 308 778 0 1 27 306 779 0 1 86 308 780 0 1 90 1 781 0 1 92 306 782 0 1 296 1 783 0 1 298 1 784 0 1 300 1 785 0 1 304 303 786 0 1 321 306 787 0 1 2477 1 788 0 1 2490 2 789 0 1 2491 1 790 0 1 2492 1 791 0 1 2495 266 792 0 1 7047 1 793 0 1 7052 1 794 0 1 7055 4 795 0 1 7057 1 796 0 1 7058 1 797 0 1 7059 1 798 0 1 7061 1 799 0 1 7064 1 800 0 1 7065 2 801 0 1 7066 1 802 0 1 7067 293 803 0 1 30941 1 804 0 1 30942 1 805 0 1 30943 1 806 0 1 30946 1 807 0 1 30950 1 808 0 1 30953 1 809 0 1 30954 1 810 0 1 30958 1 811 0 1 30959 1 812 0 1 30964 2 813 0 1 30965 1 814 0 1 30966 1 815 0 1 30967 2 816 0 1 30968 1 817 0 1 30970 2 818 0 1 30972 3 819 0 1 30973 1 820 0 1 30976 1 821 0 1 30977 203 Subset(df,df$ FwdDataVols_bin>30 && df$ FwdDataVols_bin<100 ) but it doesn't work Is there any other way to retrieve data between range 30-100 Thanks K.Ravichandra [[alternative HTML version deleted]]
Dieter Menne
2008-Nov-10 08:37 UTC
[R] is there any way to apply mulitiple conditions in subset function
Kurapati, Ravichandra (Ravichandra <ravichandra.kurapati <at> alcatel-lucent.com> writes:> > > df > > Session_Setup DCT FwdDataVols_bin counts > > 761 0 1 1 87162 > > > Subset(df,df$ FwdDataVols_bin>30 && df$ FwdDataVols_bin<100 ) but it > doesn't work >There is a subtle difference between && and &. If I am in doubt, I first make and isolated printout of the logical selection vector df=data.frame(FwdDataVols=100+rnorm(10)*100) df$FwdDataVols>10 && df$FwdDataVols<100 # gives FALSE df$FwdDataVols>10 & df$FwdDataVols<100 # gives FALSE TRUE FALSE..... subset(df,df$FwdDataVols>10 & df$FwdDataVols<100) # Probably more usual, but maybe more difficult to understand df[df$FwdDataVols>10 & df$FwdDataVols<100,] Dieter