[R] list manipulation

Thompson, David (MNR) David.John.Thompson at ontario.ca
Tue May 6 20:35:54 CEST 2008


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



More information about the R-help mailing list