Re: [R] computing a subset using a loop

2012-07-16 Thread burton030
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@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.


Re: [R] computing a subset using a loop

2012-07-16 Thread jim holtman
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 burto...@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@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.

__
R-help@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.


[R] computing a subset using a loop

2012-07-15 Thread burton030
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
albapointID==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@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.


Re: [R] computing a subset using a loop

2012-07-15 Thread jim holtman
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 burto...@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
 albapointID==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@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.

__
R-help@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.


Re: [R] computing a subset using a loop

2012-07-15 Thread burton030
http://r.789695.n4.nabble.com/file/n4636585/Baumdaten_aufbereitet.csv
Baumdaten_aufbereitet.csv 

Here you have an overview about my data frame...

--
View this message in context: 
http://r.789695.n4.nabble.com/computing-a-subset-using-a-loop-tp4636564p4636585.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] computing a subset using a loop

2012-07-15 Thread burton030
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...

http://r.789695.n4.nabble.com/file/n4636591/A_SEF_Abies_alba.csv
A_SEF_Abies_alba.csv 

--
View this message in context: 
http://r.789695.n4.nabble.com/computing-a-subset-using-a-loop-tp4636564p4636591.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] computing a subset using a loop

2012-07-15 Thread jim holtman
Here is an example of using your data to split it into the subsets and
then computing a summary of each subset.  You have to remember that
what is returned from 'split' is a 'list' of 'data.frames' that as the
subsets that you want and then use use 'lapply' to process each of the
subsets in the list.

 df - read.table(C:\\Documents and Settings\\kon9407\\My 
 Documents\\Downloads\\Baumdaten_aufbereitet (1).csv
+ , sep = ';'
+ , as.is = TRUE
+ , header = TRUE
+ )
 # split the data into a list of dataframe
 df.s - split(df, list(df$Plot..ID., df$Baumart), drop = TRUE)
 head(names(df.s), 20)
 [1] A_2_1.Abies alba A_2_2.Abies alba A_2_3.Abies alba A_2_4.Abies alba
 [5] A_2_5.Abies alba A_2_6.Abies alba A_3_1.Abies alba A_3_4.Abies alba
 [9] A_3_5.Abies alba A_3_6.Abies alba A_4_1.Abies alba A_4_3.Abies alba
[13] A_4_4.Abies alba A_4_5.Abies alba A_4_6.Abies alba B_1_2.Abies alba
[17] B_1_4.Abies alba B_1_5.Abies alba B_1_6.Abies alba B_2_4.Abies alba
 df.s[1]
$`A_2_1.Abies alba`
  X Plot..ID. Alter.Neuer.Wald Hoehe..m. Radius..cm.  Familie
  BaumartDeutsch
1 1 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
2 2 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
3 3 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
4 4 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
5 5 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
6 6 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
7 7 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
8 8 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
9 9 A_2_12   6475,64 Kieferngewaechse
Abies alba Weisstanne
 Englisch Umfang..cm.DBH..cm. Gehoelz Bemerkungen
Fotos Waldart pointID
1 European silver fir  38 12,09577569   0
NA SEF A_2_SEF
2 European silver fir  NANA   1
NA SEF A_2_SEF
3 European silver fir  NANA   1
NA SEF A_2_SEF
4 European silver fir  NANA   1
NA SEF A_2_SEF
5 European silver fir  NANA   1
NA SEF A_2_SEF
6 European silver fir  NANA   1
NA SEF A_2_SEF
7 European silver fir  NANA   1
NA SEF A_2_SEF
8 European silver fir  NANA   1
NA SEF A_2_SEF
9 European silver fir  NANA   1
NA SEF A_2_SEF
  transectID DBH_inch  age
1  A_SEF 4,76211641338583 35,7158731003937
2  A_SEF NA NA
3  A_SEF NA NA
4  A_SEF NA NA
5  A_SEF NA NA
6  A_SEF NA NA
7  A_SEF NA NA
8  A_SEF NA NA
9  A_SEF NA NA


 lapply(df.s, summary)  # notice the names of each of the subsets is printed
$`A_2_1.Abies alba`
   X  Plot..ID. Alter.Neuer.Wald   Hoehe..m.
Radius..cm.
 Min.   :1   Length:9   Min.   :2Min.   :647
Length:9
 1st Qu.:3   Class :character   1st Qu.:21st Qu.:647   Class
:character
 Median :5   Mode  :character   Median :2Median :647   Mode
:character
 Mean   :5  Mean   :2Mean   :647
 3rd Qu.:7  3rd Qu.:23rd Qu.:647
 Max.   :9  Max.   :2Max.   :647

   FamilieBaumartDeutschEnglisch
   Umfang..cm.
 Length:9   Length:9   Length:9   Length:9
  Min.   :38
 Class :character   Class :character   Class :character   Class
:character   1st Qu.:38
 Mode  :character   Mode  :character   Mode  :character   Mode
:character   Median :38

  Mean   :38

  3rd Qu.:38

  Max.   :38

  NA's   :8
   DBH..cm.Gehoelz   Bemerkungen Fotos
  Waldart
 Length:9   Min.   :0.   Length:9   Mode:logical
Length:9
 Class :character   1st Qu.:1.   Class :character   NA's:9
Class :character
 Mode  :character   Median :1.   Mode  :character
Mode  :character
Mean   :0.8889
3rd Qu.:1.
Max.   :1.

   pointID   transectID  DBH_inch age
 Length:9   Length:9   Length:9   Length:9
 Class :character   Class :character   Class :character   Class :character
 Mode  :character   Mode  :character   Mode  :character   Mode  :character





$`A_2_2.Abies alba`
   X   Plot..ID. Alter.Neuer.Wald   Hoehe..m.
Radius..cm.
 Min.   :12   Length:1   Min.   :2Min.   :660
Length:1
 1st Qu.:12   Class :character   1st Qu.:2