[R] Object of type 'closure' not subsettable

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Dec 21 14:54:43 CET 2009


On Mon, Dec 21, 2009 at 1:43 PM, Muhammad Rahiz
<muhammad.rahiz at ouce.ox.ac.uk> wrote:
> Thanks Barry for the clarification.
>
> With regards to the following;
>
> d2[[i]] <- file[[i]] - mean
>
> renamed to
>
> d2[[i]] <- f[[i]] - m
>
> The object f contains the following so clearly f is subsettable
>
> [[1]]
>  V1
> 1 10
> 2 10
> 3 10
>
> [[2]]
>  V1
> 1 11
> 2 11
> 3 11
>
> [[3]]
>  V1
> 1 12
> 2 12
> 3 12
>
> My plan is to subtract m from each subset of f and to store the output as
> each individual subsets. So,
>
> output1 <- f[[1]] - m
> output2 <- f[[2]] - m
> output3 <- f[[3]] - m
>
> If I run the following to achieve the desired result, there is an error as
> written in the subject heading.
>
> d2[[i]] <- f[[i]] - m
>
> If I run the following, the error is gone but I'm not getting the output for
> each individual file I require
>
> d2 <- f[[i]] - m
>
> The issue is, how do I make d2 subsettable?
>
>

 Well you haven't shown us this time how you initialised d2. Create it
as an empty list:

 d2 <- list()

and then you can do:

 > d2[[1]]=c(1,2,3)
 > d2[[2]]=c(4,5,6)
 > d2
[[1]]
[1] 1 2 3

[[2]]
[1] 4 5 6

 As I said, read one of the basic R documents linked on the
documentation section of the R web site, and play with lists and
vectors for a while.

Barry




More information about the R-help mailing list