Skip to content
Prev 169014 / 398506 Next

Difference between a[[i]] and a[i]

Rolf Turner wrote:
what do you mean by 'can be considered to be a list'?  by whom?  not by
the r interpreter, it seems:

v = 1:10
# a vector
l = as.list(1:10)
# a list

is.list(v)
# no
is.list(l)
# yes

is(v, "list")
# no
is(l, "list")
# yes

is(v)
# "integer" "vector" "numeric" "data.frameRowLabels"
is(l)
# "list" "vector"

d = data.frame(x=1:10)
aggregate(d, by=v)
# error: 'by' must be a list
aggregate(d, by=l)
# fine

sort(l)
# error: have you called 'sort' on a list?
sort(v)
# fine, no error

# and the best of all
sort.list(l)
# error: have you called 'sort' on a list?
sort.list(v)
# fine, no error

perhaps you'd care to explain what 'can be considered to be a list' is
supposed to mean precisely, or else you're messing things up.

vQ