I hope this toy example gives an idea to understand the problems that
you are facing now. Please see the below:
# 1. Create an empty list
> A <- list()
> A
list()
# 2. Add the first component (vector with two elements).
> A[[1]] <- c(2,6)
> A
[[1]]
[1] 2 6
# 3. Now, add the third component (vector with three elements).
# I did not add the second component INTENTIONALLY.
> A[[3]] <- c(1,3,2)
> A
[[1]]
[1] 2 6
[[2]]
NULL
[[3]]
[1] 1 3 2
# I see the second element has NULL value.
# You can apply 'is.null()' to this second component.
> is.null(A[[2]])
[1] TRUE
# However, you will see the error as below if 'is.null()' is used for
the fourth component.
> is.null(A[[4]])
Error in A[[4]] : subscript out of bounds
# Why? It is because the list 'A' has only three components.
> length(A)
[1] 3
>
I hope this helps. I would appreciate if you DO READ the posting guide.
Chel Hee Lee
On 1/20/2015 9:30 AM, Ragia Ibrahim wrote:> Hello,
> kindly ,
> how to catch this Error
> Error in A[[i]] : subscript out of bounds
> and check that the list is empty is.null( A[[i]] ) do no twork
> thanks in advance
> R.I
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>