[R] Summarizing select columns in a data frame

Bernard McGarvey mcg@rvey@bern@rd @end|ng |rom comc@@t@net
Sun Jan 17 21:15:38 CET 2021

I have a data frame that consists of several factor columns say A, B, C, D, and E and several columns containing numerical data, say X1, X2, .... X10. I would like to create statistics of some of the numerical columns by some of the factor columns. For example,

Calculate the mean, min, and max of variables X1 and X7, by factors A, and E. The results should look like the table below:

Factor A Factor E     mean(X1) min(x1) max(X1) mean(X7) min(x7) max(X7) mean(X10) min(x10) max(X10)
A1        E1
A1        E2
A1        E3
A2        E1
A2        E2
A2        E3

I would like the results to be returned to a data frame or other object that I can write out using the write.csv function. I have looked at the summarize and numSummary functions but they do not appear to be flexible enough to do the above.

Any help would be appreciated,


Bernard McGarvey
Director, Fort Myers Beach Lions Foundation, Inc.
Retired (Lilly Engineering Fellow).

More information about the R-help mailing list