Discarding non-decimal values in R

I've got the a data frame called "odds" in R containing a couple of odds I kept track of in several formats:

timestamp   RX  R1  R2
2013-04-13 00:26:49 3.65    1.50    7.00
2013-04-13 00:26:49 3.70    1.50    8.00
2013-04-13 00:26:49 +375    -250    +860
2013-04-13 00:35:01 3.65    1.50    7.00
2013-04-13 00:35:01 3.70    1.50    8.00
2013-04-13 00:35:01 3.70    1.45    7.00
2013-04-13 00:36:55 +320    -250    +600
2013-04-13 01:00:01 3.65    1.50    7.00
2013-04-13 00:36:55 3.70    1.50    8.00
2013-04-13 00:36:55 3.70    1.45    7.00

How can discard the rows not in decimal format?

In the example I just gave, the third and the seventh rows should have been deleted entirely.

Cheers

Answers


# Assuming myDF is your data.frame
myDF[abs(as.numeric(myDF$RX)) < 100, ]

             timestamp   RX   R1 R2
1  2013-04-13 00:26:49 3.65 1.50  7
2  2013-04-13 00:26:49 3.70 1.50  8
4  2013-04-13 00:35:01 3.65 1.50  7    <~~~  Third Row is gone
5  2013-04-13 00:35:01 3.70 1.50  8
6  2013-04-13 00:35:01 3.70 1.45  7
8  2013-04-13 01:00:01 3.65 1.50  7    <~~~  So is the 7th Row
9  2013-04-13 00:36:55 3.70 1.50  8
10 2013-04-13 00:36:55 3.70 1.45  7

Note: If RX is a factor, then you need to use as.numeric(as.character(RX)) instead of just as.numeric(RX)


Edit as per concern in the comments:

The above example is based on copying+pasting the OP sample data. If the process is not working for you, then that indicates that there is a difference between your real data and the sample data.

Take a look at the differences and that will help lead you in the right direction.


Need Your Help

Flex and OOP customs for simple getters and setters

flex oop

I am having a little play with Flex and I'm curious as to a few things.

Is there only one transport type for MojoX::Session?

perl mojolicious

Is there only one transport type for MojoX::Session, MojoX::Session::Transport::Cookie? I could not find any other transport type.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.