I cannot figure out how to do this. I have a data.frame in R. It looks like this:
Scores <- read.table(text = "
ID Test1 Test2 Test3 Final
1 Student1 20 23 21 48
2 Student2 16 15 18 36
3 Student3 25 20 22 40
4 Student4 14 19 18 42
5 Student5 10 15 14 30
")
What I want is to create a new data object that has the range of values for each test, including the final. So it will look something like this:
result <- read.table(text = "
min max
Test1 10 25
Test2 15 23
Test3 14 22
Final 30 48
")
It honestly doesn't matter to me whether it just lists the max and min values, or actually calculate the difference. I just can't figure out a way to implement this that isn't unnecessarily complicated. I know I can pull the columns out manually and individually, but there must be some better way of doing this. Something involving by()
or tapply()
? But I just cannot get them to work.
Any ideas?