The lines > #maxcls<-dset[,2] > #mincls<-dset[,2] which you have shown commented out select a full column. You probably want the min and max of that column. With your definitions, mincls:maxlcs has the same type of behavior as (1:3):(1:3)