2

Stargazer package gives me really nice descriptive table to include in latex document.

library(stargazer)
stargazer(attitude)

enter image description here

Is it possible to add a column reporting number of NAs for each of the variables?

Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
radek
  • 7,240
  • 8
  • 58
  • 83
  • I haven't seen `stargazer` tag being used in previous questions and don't have enough reputation to create it. Would it make a sense to add it? – radek Apr 04 '13 at 23:04
  • 1
    I don't think so, but mail to the developer - I believe he will be happy to implement this. – EDi Apr 04 '13 at 23:17

2 Answers2

1

This snippet will give you the number of NAs per row and column in a data frame

# make some data
count <- 10
data <- data.frame( a=runif(count), b=runif(count))

# add some NAs
data[data$a>0.5,]$a <- NA
data[data$b>0.5,]$b <- NA

# NAs per row
data$NACount <- apply(data, 1, function(x) {length(x[is.na(x)])})

# NAs per column
NACountsByColumn <- lapply(data, function(x) {length(x[is.na(x)])} )
sharoz
  • 6,157
  • 7
  • 31
  • 57
0

The "N" column of stargazer does not count the NAs. Alhough there is not direct way to input NAs in the output table, you can simply calculate it by

nrow(dataset) - the number in "N" column

derp92
  • 468
  • 5
  • 5