[R] Simple extraction of level,x,y from contourLines()

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Oct 22 21:10:38 CEST 2009


On 22-Oct-09 19:03:06, Duncan Murdoch wrote:
> On 22/10/2009 2:57 PM, (Ted Harding) wrote:
>> A follow-up to my previous query.
>> 
>> Say one of the results returned by contourLines() is
>> 
>>   C.W <- contourLines(....)
>> 
>> Then C.W is a list of (in this case 28) lists,
>> each of which is a list with components $level (a single number),
>> $x (the x coords of the points on a contour at that level) and
>> $y (the y coords).
>> 
>> I can of course get these individually with, for the 5th one for
>> instance,
>> 
>>   C.W[[5]]$level
>>   C.W[[5]]$x
>>   C.W[[5]]$y
>> 
>> But I can't see how to obtain, in one line and without running
>> a nasty loop, to get all the levels at once!
>> 
>> In other words, I'm looking for an expression which will return
>> the vector
>> 
>>   c(C.W[[1]]$level,C.W[[2]]$level,...,C.W[[28]]$level)
> 
> sapply(C.W., function(x) x$level)
> 
> should do it.  (It will contain repeats if your contours have gaps in 
> them; unique() can remove those.)
> 
> Duncan Murdoch

Excellent! That does do it. Indeed, It is precisely to identify
the "broken" contours that I want the set of levels, so the repeats
are what I'm looking for!

Thanks Duncan,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 22-Oct-09                                       Time: 20:10:34
------------------------------ XFMail ------------------------------




More information about the R-help mailing list