# [R] Taking the Average of a subset of data

Isaac Barnhart |hb @end|ng |rom k@u@edu
Fri Feb 15 16:06:46 CET 2019

```Hello all, I have another question. I'm working with the following dataset:

plot    plant   leaf_number     sen_score       plot_lai        plant_lai       lai_score       leaf_num
104     5       1       90      104     1       82      1
104     5       2       90      104     1       167     2
104     5       3       95      104     1       248     3
104     5       4       100     104     1       343     4
104     6       1       95      104     1       377     5
104     6       2       85      104     1       372     6
104     6       3       90      104     1       335     7
104     6       4       90      104     1       221     8
105     5       1       90      104     1       162     9
105     5       2       95      104     2       145     1
105     5       3       100     104     2       235     2
105     5       4       100     104     2       310     3
105     6       1       70      104     2       393     4
105     6       2       80      104     2       455     5
105     6       3       90      104     2       472     6
105     6       4       80      104     2       445     7
106     5       1       100     104     2       330     8
106     5       2       90      104     2       292     9
106     5       3       100     105     1       64      1
106     5       4       100     105     1       139     2
106     5       10      0       105     1       211     3
106     6       1       100     105     1       296     4
106     6       2       30      105     1       348     5
106     6       3       100     105     1       392     6
106     6       4       40      105     1       405     7
108     5       1       100     105     1       379     8
108     5       2       100     105     1       278     9
108     5       3       100     105     2       64      1
108     5       4       100     105     2       209     2

(Note: 'plant' and 'leaf' column should be separated. '51' means plant 5, leaf 1).

This dataset shows two datasets: The left 4 columns are of one  measurement (leaf senescence), and the right 4 columns are of another (leaf area index). I have a large amount of plots, and several plants, more than what is listed.

I need to sort both datasets (senescence and leaf area index) so that each plot has the same number of leaves.

This is hard because sometimes plots in the 'senescence' dataset have more leaves, and sometimes plots in the 'leaf area index'. Is there a way to sort both datasets so that this requirement is met? Like I said, there is no way to tell which dataset has the plot with the minimum amount of leaves; it can be either one in any case.

Any help would be appreciated!

Isaac

[[alternative HTML version deleted]]

```