[R] Data frame search and remove questions

Douglas M. Hultstrand dmhultst at metstat.com
Thu Oct 15 19:17:07 CEST 2009


Hello,

I have a couple questions about removing rows from a data frame and 
creating a new data frame with the removed values.  I provided an 
example data frame (d) below.

Questions:
1) How can I search for "-999.000" and remove the entire row from data 
frame "d"? (all -999 values will be in sd_diff)
2) Can I create a new data frame "d.new" that only contains the removed 
rows?
3) How can I remove the last two rows from a data frame.  (I used append 
command to add two values to the end of the data)

 > d
   lat.add lon.add PPT.add Z.add sd_dif
1    37.67  -95.48   1.000   368  1.017
2    38.82  -92.22  13.208   383  5.737
3    37.30  -95.50   6.096   130  4.377
4    37.08  -95.57   0.508   106  -999.000
5    38.73  -93.55   6.350   370  6.233
6    38.83  -94.88   0.254     5  8.607
7    38.33  -96.18   0.508    43  8.665
8    38.85  -94.73   1.000     5  -999.000
9    38.71  -93.16   1.016   320  3.717
10   38.95  -95.67   1.000     5  8.553

 > d.new
   lat.add lon.add PPT.add Z.add sd_dif
1    37.08  -95.57   0.508   106  -999.000
2    38.85  -94.73   1.000     5  -999.000


Thanks for all the help,
Doug

-- 
---------------------------------
Douglas M. Hultstrand, MS
Senior Hydrometeorologist
Metstat, Inc. Windsor, Colorado
voice: 970.686.1253
email: dmhultst at metstat.com
web: http://www.metstat.com




More information about the R-help mailing list