Skip to content

Attempting to recode elements contained in a list

2 messages · Greg Blevins, Brian Ripley

#
Hello R-Masters,

I have a list 's' with three elements, as shown below.  I want to recode a.a,  a.a2, and a.a3 to NA if the value in a.a is less than 3.  

I reivewed my Modern Applied Statistic Book, the online help and did some searching of R-help on the internet. I explored unlist and as.list.data.frame in an attempt to isolate the third element of the list s, but this was not helpful. Any help would be appreciated.
[1] 342   3
[1] "scan" "time" "a"
scan               time a.a a.a2 a.a3
202       Plastic lids       Plastic lids NaN  NaN  NaN
195       Plastic lids      Cookware lids  44   31   58
205       Plastic lids  Seasoning packets   9    4   20
191       Plastic lids      Baking sheets  15    7   27
209       Plastic lids           Utensils   9    4   20
194       Plastic lids        Cell phones   0    0    7
193       Plastic lids       Canned goods   0    0    7
197       Plastic lids    Hand/dish towel   3    0   12

Thank you.

Greg Blevins
The Market Solutions Group

Windows xp, 2.1.1

Gregory L. Blevins
Vice President, Partner
The Market Solutions Group, Inc.
gblevins at marketsolutionsgroup.com
Office phone: 612 392-3163
Cell phone: 612 251-0232
"What is at the beginning but a small error, swells to huge proportions at the close." Aristotle
#
On Wed, 24 Aug 2005, Greg Blevins wrote:

            
I think s is a data frame, and you are looking at its printout.  There is 
almost certainly no element a.a.  Rather, the data frame has a column a, 
which is probably a matrix with three columns, a, a2 and a3. Use str(s) to 
be sure.  Here is an attempt to create a similar object
"a3")))
scan time      a.a     a.a2     a.a3
1    a    A 5.435430 1.283933 1.546180
2    b    B 5.169964 2.519836 1.568225
3    c    C 3.844045 2.318089 0.772869

If that is the case, you need

s$a[s$a[, "a"] < 3, ] <- NA