[R] Splitting a vector
Gerrit Eichner
Gerrit.Eichner at math.uni-giessen.de
Wed Dec 11 10:19:02 CET 2013
Hello, Long Vo,
take a look at the help page of split or directly at
str(Y)
They tell you that Y is a list, and list components are indexed using
"[[":
mean(Y[[4]])
should do what you want.
Regards -- Gerrit
> This does what I needed. However, as the output is a list object, is there
> any way to apply a function to such object? For example if I want to compute
> the mean for the 4th subvectors, I can't simply use:
> #####
> Y=split(X,as.numeric(gl(length(X),3,length(X))))
> mean(Y[4])
> #####
> as the error message shows "argument is not numeric or logical"
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Splitting-a-vector-tp4681930p4681987.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
More information about the R-help
mailing list