Your 'x' has length 2, so x[[3]] cannot be calculated ('subscript out of
bounds' is what I get). You can check for this with length(x)3.
In general, you want to be more precise: 'does not have a value', 'is
NULL', and 'is empty' are not synonymous. I'm not sure what 'does not have
a value'
Hello,
Kindly I have a list of lists as follow
x
[[1]]
[1] 7
[[2]]
[1] 3 4 5
as showen x[[3]] does not have a value and it has NULL, how can I check on this
how to test if x[[3]] is empty.
thanks in advance
Ragia
[[alternative HTML version
Hi,
On Dec 20, 2014, at 10:58 AM, Ragia Ibrahim ragi...@hotmail.com wrote:
Hello,
Kindly I have a list of lists as follow
x
[[1]]
[1] 7
[[2]]
[1] 3 4 5
as showen x[[3]] does not have a value and it has NULL, how can I check on
this
how to test if x[[3]] is empty.
In general
Hello,
Your list seems to have only 2 elements. You can check this with
length(x)
Or you can try
lapply(x, is.null)
Hope this helps,
Rui Barradas
Em 20-12-2014 15:58, Ragia Ibrahim escreveu:
Hello,
Kindly I have a list of lists as follow
x
[[1]]
[1] 7
[[2]]
[1] 3 4 5
as showen x[[3]]
This can be tricky, because depending on what the missing object is, you can
get either NULL, NA, or an error. Moreover is.na() behaves differently when
evaluated on its own, or as the condition of an if() statement. Here is a
function that may make life easier. The goal is NOT to have to pass
Boris et. al:
Indeed, corner cases are a bear, which is why it is incumbent on any
OP to precisely define what they mean by, say, missing,
null,empty, etc.
Here is an evil example to illustrate the sorts of nastiness that can occur:
z - list(a=NULL, b=list(), c=NA)
with(z,{
+
This may be out of context, but on the face of it, this claim is wrong:
On 20/12/2014, 1:57 PM, Boris Steipe wrote:
Moreover is.na() behaves differently when evaluated on its own, or as
the condition of an if() statement.
The conditions in an if() statement are not evaluated in special
Thanks. This is what I was referring to:
x - rep(NA, 3)
is.na(x)
[1] TRUE TRUE TRUE
if (is.na(x)) {print(True)}
[1] True
Warning message:
In if (is.na(x)) { :
the condition has length 1 and only the first element will be used
You are of course right - the warning is generated by if(), not by
8 matches
Mail list logo