sub-setting based on categorical variable in R
This question seemed to be more suitable for general stackoverflow since it's a R question.

I'm using data.table. The syntax is a little bit different from data.frame, but the time spent on learning data.table is well worth the effort. See more tutorials on wiki, and this good sheet.

library(data.table)
s = "rowname    group   marks   upd
2   C   3   up
3   C   4   down
6   C   7   up
1   T   2   up
4   T   5   up
5   T   6   down
7   T   1   middle
8   T   0   down"
# fread is the fastest csv reader
a = fread(s) 
# the i in data.table[i,j] subset rows, empty j select all columns
upd_subset = a[upd %in% c('down','middle'),]

&gt; upd_subset
   rowname group marks    upd
1:       3     C     4   down
2:       5     T     6   down
3:       7     T     1 middle
4:       8     T     0   down

&gt; upd_subset_bygroups = split(upd_subset, upd_subset$group)
&gt; upd_subset_bygroups
$C
   rowname group marks  upd
1:       3     C     4 down

$T
   rowname group marks    upd
1:       5     T     6   down
2:       7     T     1 middle
3:       8     T     0   down