On this day 28/08/2006 19:20, Muhammad Subianto wrote:
> Dear all,
> I am still working with "list".
> If I have an empty list how can I remove from list data.
> Here is a toy example:
> x <- list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5,
> 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4))
> y <- list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1),c(1, 1, 1, 1, 1),c(1,
> 1, -1, 1, -1),c(-1, -1, -1, -1, -1))
> ## Thanks to Gabor Grothendieck for this trick.
> ## SIMPLIFY? SIMPLIFY >< simplify
> xy.list <- mapply(cbind, x, y, SIMPLIFY=FALSE)
>
> point.class <- t(cbind(c(10,20,15,4,-1),c(21,10,15,34,-1),c(11,13,6,3,1),c(7,5,5,2,1),c(8,9,5,12,-1)))
> class.diffsame <- points.neighb(as.matrix(point.class), xy.list, 5)
> pd.class <- points.diff(class.diffsame,xy.list)
>
> nc.test <- vector("list",length(pd.class))
> for (i in 1:length(pd.class)) {
> nc.test[[i]] <- pd.class[[i]]$point.diff
> }
> nc.test
>> nc.test> [2,] 4 9 14 19 1
> [[1]]
> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 6 11 16 1
Dear
Jim Holtman and Gabor Grothendieck,
Thank you both very much for the suggestions!
These is exactly what I was looking for.
Best wishes, Muhammad Subianto
## delete null/empty entries in a list
delete.NULLs <- function(x.list){
x.list[unlist(lapply(x.list, length) != 0)] }
> delete.NULLs <- function(x.list){
+ x.list[unlist(lapply(x.list, length) != 0)]
+ }
> delete.NULLs <- function(x.list){
+ x.list[unlist(lapply(x.list, length) != 0)]
+ }
>
> delete.NULLs(nc.test)
[[1]]
[,1] [,2] [,3] [,4] [,5]
[1,] 1 6 11 16 1
[2,] 4 9 14 19 1
[3,] 5 10 15 20 1
[[2]]
[,1] [,2] [,3] [,4] [,5]
[[3]]
[,1] [,2] [,3] [,4] [,5]
[1,] 3 8 13 18 -1
[2,] 5 10 15 20 -1
>
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.
Archive generated by hypermail 2.1.8, at Tue 29 Aug 2006 - 06:25:37 EST.
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.