[R-sig-teaching] length of vectors with tapply

Steven Stoline sstoline at gmail.com
Wed Sep 10 05:12:21 CEST 2014


Dear All:

I was trying to get the lengths of vectors using "length" in tapply as
follows:

ni<-tapply(data[,2], data[,2], length, na.rm=TRUE)

but it did not work for me. I am not sure what I am doing wrong.

I am not sure if I should use different function.

Here is the data:
============
data<-matrix(c(8,24,0,0,16,32,6,0,16,7,4,4,9,5,8,18,2,0,4,0,8,3,1,5,24,12,2,8,1,8,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3),30,2)



The answer should be:

ni: 18  ,  10  ,  2


thank you very much
Steven

-- 
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
sstoline at gmail.com

	[[alternative HTML version deleted]]



More information about the R-sig-teaching mailing list