[R] list manipulation

Thompson, David (MNR)
Wed, 07 May 2008 12:46:58 -0000

Beautiful! Thanks Jim.

DaveT.
>-----Original Message-----
>From: jim holtman [mailto:jholtman at gmail.com]
>Sent: May 6, 2008 07:33 PM
>To: Thompson, David (MNR)
>Subject: Re: [R] list manipulation
>
>The reason for the NULLs is that is the output of the lapply you are
>executing.  If you don't want to see the value, then use
'invisible'
>or assign to an object since you are executing this at the command
>level, the default is to print the value.
>
>invisible(lapply(...))
>
>On Tue, May 6, 2008 at 2:35 PM, Thompson, David (MNR)
><David.John.Thompson at ontario.ca> wrote:
>> Hello,
>>
>> I have a set of one-liners (many thanks to previous
>responses from this
>> list) that I use to look at newly imported data sets with
>functions like
>> dim(), names(), str(), etc. within lapply(). Generally,
>these commands
>> work for me but, I am apparently still missing some aspect of list
>> manipulation. I don't understand why I get a set of NULL
>list elements
>> at the end of each output as demonstrated below. How can I
>generate this
>> (and similar) result(s) without all the trailing NULLs?
>>
>> > lapply(ls(pattern='bn'), function(x) cat(x, dim(get(x)),
"\t",
>> names(get(x)), "\n"))
>> bn1993 2885 11   oplt rplt rsiz tree bd ht oaz odst raz rdst spr
>> bn1994 3158 7    oplt tree bd ht spr stat dam
>> bn1995 734 7     oplt tree bd ht spr stat dam
>> bn1996 293 7     oplt tree bd ht spr stat dam
>> bn1997 264 7     oplt tree bd ht spr stat dam
>> bn1998 768 7     oplt tree bd ht spr stat dam
>> bn1999 654 7     oplt tree bd ht dbh stat dam
>> bn2003 1407 9    oplt tree bd94 ht94 ht99 ht02 ht03 stat dam
>> [[1]]
>> NULL
>>
>> [[2]]
>> NULL
>>
>> [[3]]
>> NULL
>>
>> [[4]]
>> NULL
>>
>> [[5]]
>> NULL
>>
>> [[6]]
>> NULL
>>
>> [[7]]
>> NULL
>>
>> [[8]]
>> NULL
>>
>> Thanx, DaveT.
>> *************************************
>> Silviculture Data Analyst
>> Ontario Forest Research Institute
>> Ontario Ministry of Natural Resources
>> david.john.thompson at ontario.ca
>> http://ofri.mnr.gov.on.ca
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
>--
>Jim Holtman
>Cincinnati, OH
>+1 513 646 9390
>
>What is the problem you are trying to solve?
>