[R] counting unique values (summary stats)

reichm@@j m@iii@g oii sbcgiob@i@@et reichm@@j m@iii@g oii sbcgiob@i@@et
Thu Mar 21 23:31:06 CET 2019


r-help

I have the following little scrip to create a df of summary stats.  I'm
having problems obtaining the # of unique values 

           unique=sapply(myData, function (x)
             length(unique(x), replace = TRUE))

Can I do that, or am I using the wrong R function?

summary.stats <- data.frame(mean=sapply(myData, mean, na.rm=TRUE), 
           sd=sapply(myData, sd, na.rm=TRUE), 
           min=sapply(myData, min, na.rm=TRUE), 
           max=sapply(myData, max, na.rm=TRUE), 
           median=sapply(myData, median, na.rm=TRUE), 
           length=sapply(myData, length),
           unique=sapply(myData, function (x)
             length(unique(x), replace = TRUE))
           miss.val=sapply(myData, function(y) 
             sum(length(which(is.na(y))))))

Jeff Reichman



More information about the R-help mailing list