[R] sum(table(v)) == length(v)

Sam Steingold sds at gnu.org
Sun Sep 16 20:34:53 CEST 2012


Is it possible to violate the identity sum(table(v)) == length(v) ??
I see no way to do that and it holds in my small examples,
but it is violated in the huge set I have:

system.time(z <- unique(data.frame(u=U,s=S)))
tab1 <- table(z$u)
tab1 <- tab1[tab1>0] # S is factor so some counts were 0
tab2 <- table(z$s)
stopifnot(length(tab2) == nrow(z)) # yes
stopifnot(sum(tab1) == nrow(z))  ### no!
sum(tab1)
728587
length(tab1)
503374
length(tab2)
2112951

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://think-israel.org http://americancensorship.org
http://ffii.org http://memri.org http://jihadwatch.org http://pmw.org.il
Live Lisp and prosper.



More information about the R-help mailing list