Skip to content
Prev 367234 / 398506 Next

use table function with data frame subsets

Readers,

Data set:

20170101,10020,A,b,Y
20170101,10020,B,b,N
20170101,10020,C,d,Y
20170102,20001,C,d,Y
20170102,20001,D,m,Y
20170102,20001,L,a,Y

testtable<-read.csv('~/tmp/data.csv',header=F)
testtablea<-testtable[grep('^10',testtable[,2]),]
V1    V2 V3 V4 V5
1 20170101 10020  A  b  Y
2 20170101 10020  B  b  N
3 20170101 10020  C  d  Y
4 20170102 20001  C  d  Y
5 20170102 20001  D  m  Y
6 20170102 20001  L  a  Y
V1    V2 V3 V4 V5
1 20170101 10020  A  b  Y
2 20170101 10020  B  b  N
3 20170101 10020  C  d  Y
N Y
   a 0 1
   b 1 1
   d 0 2
   m 0 1
N Y
   a 0 0
   b 1 1
   d 0 1
   m 0 0

Wy do values for rows beginning 'a' and 'm' appear when they do not 
satisfy the regular expression for the object 'testtablea'?

Please, how to use the 'table' function to show:
N Y
   b 1 1
   d 0 1

Thanks.