问题
I am not sure why it seems so difficult to find information regarding summarizing non-quantitative variables with stargazer.
I would like a summary of the following time variable (number of observations, min and max value would be great)
Time<-c("2014-07-03 10:57:35 PDT", "2014-07-03 11:02:35 PDT",
"2014-07-03 11:07:35 PDT", "2014-07-03 11:12:35 PDT",
"2014-07-03 11:17:34 PDT", "2014-07-03 11:22:34 PDT")
Time<-as.POSIXlt(Time, format="%Y-%M-%d %H:%M:%S")
And a overall sample size and number of values of each category of the following factor.
Cat.Var<-rep(c("Level 1","Level 2"), each=3)
This seems so basic but there seems to be almost no documentation related to an issue like this. Maybe the Stargazer package is not what I should be using, but I would like these tables to visually match other output I have that was created with Stargazer.
Thank you!
回答1:
Stargazer is capable of producing a well formatted summary table of factor variable. Just feed the factor variables into the ftable function from base r, and then feed that into stargazer.
For example:
stargazer(ftable(data.set$gender, data.set$year), type="text")
This summarizes the gender distribution of your data for each year. Stargazer requires ftable to have at least two factor variables, otherwise it produces an error, but this is very easy to get around if you just create a factor variable of 1's for every observation.
来源:https://stackoverflow.com/questions/25473689/summarizing-factors-and-times-with-stargazer