I have a data frame as shown below:
group respondent nteachers totalq3 totalq4 totalq5 totalq6 totalq7
1 2 You 2 5 4 4 5 5
2 2 Your Teachers 2 10 8 9 10 10
119 1001 All Principals NA NA NA NA NA NA
120 1002 All Teachers NA NA NA NA NA NA
There are additional vectors that go beyond totalq7 (through totalq53) but this snippet of data should suffice.
What I need is some way of identifying vectors totalq3 through totalq53 in descending order of the values for “Your Teachers”. Then I flag the 5 vectors with the highest values for “Your Teachers” and output these 5 to xtable. Finally the process has to be repeated to identify the 5 vectors with the smallest values for “Your Teachers”.
What is the trick here? Any and all tips would be much appreciated.
Ani
With a dataframe named ‘dat’, this would be the column names in the order of the second row of ‘dat’.
So the highest five respondent values would be in:
And the column names with the five lowest values:
To get the reduced dataset for passage to xtable, just use “heads or tails”:
Here is the test set: