[R] computing a subset using a loop

jim holtman jholtman at gmail.com
Sun Jul 15 20:43:24 CEST 2012


I looks like you want to use the 'split' function which would create a
list of dataframes with the various conditions:

result <- split(Baumdaten, list(Baumdaten$transectID,
Baumdaten$Baumart), drop = TRUE)

On Sun, Jul 15, 2012 at 11:31 AM, burton030 <burton69 at hotmail.de> wrote:
> Dear all,
>
> I have a data frame with different variables and I want to build different
> subsets out of this data frame using some conditions and I want to use a
> loop because there will be a lot of subsets and this would be saving a lot
> of time.
>
> I try to give you an overview about my data frame. I have a data frame named
> "Baumdaten" and it has one column named "transectID" with different IDs
> (A_SEF ,A_LEF, B_SEF etc.) there is another column named "Baumart" with
> different species like Abies alba, Betula pendula, etc. I want to build now
> subsets and the first subset should be named A_2_SEF_Abies_alba and should
> contain all Abies alba that are living in A_2_SEF. So the normal code would
> be
>
> A_2_SEF_Abies_alba<-subset(Baumdaten,Baumart=="Abies
> alba"&pointID=="A_2_SEF")
>
>  The following step would be to replace Abies alba with Betula pendula and
> so on after doing this for A_SEF I have to start with A_LEF so a lot of time
> is needing thats why I want to ask if it is possible doing this by using a
> loop? Hope you can understand my problem...
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/computing-a-subset-using-a-loop-tp4636564.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