# computing a subset using a loop

7 messages
Open this post in threaded view
|

## computing a subset using a loop

 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...
Open this post in threaded view
|

## Re: computing a subset using a loop

 Baumdaten_aufbereitet.csvHere you have an overview about my data frame...
Open this post in threaded view
|

## Re: computing a subset using a loop

 In reply to this post by burton030 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 <[hidden email]> 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. > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: computing a subset using a loop

 Hi, thanks for your reply but this code just gives me a list but no subsets but I need subsets because I want to do some calculations with these subsets and want do make some plots etc. Is there a solution for my problem? I ve posted an example for the first subset... A_SEF_Abies_alba.csv
Open this post in threaded view
|