[R] melt, remove rows with common id if NA encountered in value

emorway emorway at engr.colostate.edu
Thu May 6 00:02:39 CEST 2010


forum,

After melting a data.frame I get some 18,000+ rows (some rows below).  I
want to filter/remove all rows that have an "SP" & "variable" value in
common with a row containing "NA" in the value column.  So in the example
rows below, all rows with SP=425 & variable=CoolidgeLoad would be removed
because NA was encountered in at least one of the rows (in this case 2 of
the rows).   Continuing the example, rows with SP=426 &
variable="CoolidgeLoad" would be retained since "NA" doesn't appear in the
value column of any row containing both of these values.  Rows with SP=361 &
variable="JMLoad" would also survive.  After performing the filter I plan to
"cast" the data.

-Eric

SP   variable     value
425  CoolidgeLoad 6.044483e+07
425  CoolidgeLoad 5.314102e+07
425  CoolidgeLoad 5.287761e+07
425  CoolidgeLoad 4.592003e+07
425  CoolidgeLoad 4.314002e+07
425  CoolidgeLoad           NA
425  CoolidgeLoad           NA
426  CoolidgeLoad 5.412465e+07
426  CoolidgeLoad 6.122925e+07
426  CoolidgeLoad 6.514926e+07
426  CoolidgeLoad 6.605055e+07
426  CoolidgeLoad 6.525006e+07
426  CoolidgeLoad 6.166645e+07
426  CoolidgeLoad 6.167510e+07
427  CoolidgeLoad 5.372381e+07
427  CoolidgeLoad 4.551596e+07
427  CoolidgeLoad 4.246508e+07
427  CoolidgeLoad           NA
427  CoolidgeLoad           NA
427  CoolidgeLoad           NA
427  CoolidgeLoad           NA
359        JMLoad 3.036887e+05
359        JMLoad           NA
359        JMLoad           NA
359        JMLoad           NA
359        JMLoad           NA
359        JMLoad 3.313669e+05
359        JMLoad 3.037101e+05
360        JMLoad 3.036887e+05
360        JMLoad 2.761196e+05
360        JMLoad           NA
360        JMLoad 3.037101e+05
360        JMLoad 3.036887e+05
360        JMLoad 3.036672e+05
360        JMLoad 3.036458e+05
361        JMLoad 3.036029e+05
361        JMLoad 3.035814e+05
361        JMLoad 3.312733e+05
361        JMLoad 3.037101e+05
361        JMLoad 3.313435e+05
361        JMLoad 3.037315e+05
361        JMLoad 3.313669e+05
-- 
View this message in context: http://r.789695.n4.nabble.com/melt-remove-rows-with-common-id-if-NA-encountered-in-value-tp2131770p2131770.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list