[R] computing a subset using a loop

jim holtman jholtman at gmail.com
Mon Jul 16 22:17:25 CEST 2012


If you just wanted to do a boxplot of one of the subset, you would do
something like:

boxplot(df.s[["A_SEF_Abies alba"]]$age)

If you wanted to do it for all the subset, then something like:

lapply(df.s, function(.sub) boxplot(.sub$age))

On Mon, Jul 16, 2012 at 11:14 AM, burton030 <burton69 at hotmail.de> wrote:
> Hi,
>
> thanks I think now I understand how it works...
>
> I m using now this code for the first specie in all my transect IDs.
>
> df.s <- split(Baumdaten, list(Baumdaten$transectID, Baumdaten$Baumart), drop
> = TRUE)
> head(names(df.s), 10)
> "A_SEF_Abies alba" "A_LEF_Abies alba" "B_SEF_Abies alba" "B_LEF_Abies alba"
> "C_SEF_Abies alba" "C_LEF_Abies alba" "D_SEF_Abies alba" "D_LEF_Abies alba"
> "E_SEF_Abies alba" "E_LEF_Abies alba"
>
>
>  But can you tell me how, I can make subsets out of one of the subsets. For
> example I want boxplot for the variable age.
>
> Is it something like this? It dosent work, I know...
>
> lapply(df.s,boxplot(A_SEF_Abies alba$Baumart))
>
> Thanks in advanced
>
> --
> View this message in context: http://r.789695.n4.nabble.com/computing-a-subset-using-a-loop-tp4636564p4636653.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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list