[R] Display a dataframe
Gang Chen
gangchen6 at gmail.com
Thu Jul 3 21:56:07 CEST 2014
I have a matrix 'dd' defined as below:
dd <- t(matrix(c(153.0216306, 1, 7.578366e-35,
13.3696538, 1, 5.114571e-04,
0.8476713, 1, 7.144239e-01,
1.2196050, 1, 5.388764e-01,
2.6349405, 1, 2.090719e-01,
6.0507714, 1, 2.780045e-02), nrow=3, ncol=6))
dimnames(dd)[[2]] <- c('# Chisq', 'DF', 'Pr(>Chisq)')
dimnames(dd)[[1]] <- c('# Sex', '# Volume', '# Weight', '# Intensity',
'# ISO', '# SEC')
'dd' displays as the following:
# Chisq DF Pr(>Chisq)
# Sex 153.0216306 1 7.578366e-35
# Volume 13.3696538 1 5.114571e-04
# Weight 0.8476713 1 7.144239e-01
# Intensity 1.2196050 1 5.388764e-01
# ISO 2.6349405 1 2.090719e-01
# SEC 6.0507714 1 2.780045e-02
I would like to display it as:
# Chisq DF Pr(>Chisq) term
153.0216306 1 7.578366e-35 # Sex
13.3696538 1 5.114571e-04 # Volume
0.8476713 1 7.144239e-01 # Weight
1.2196050 1 5.388764e-01 # Intensity
2.6349405 1 2.090719e-01 # ISO
6.0507714 1 2.780045e-02 # SEC
This is what I came up with
(cc <- data.frame(data.frame(dd), term=dimnames(dd)[[1]]))
X..Chisq DF Pr..Chisq. term
# Sex 153.0216306 1 7.578366e-35 # Sex
# Volume 13.3696538 1 5.114571e-04 # Volume
# Weight 0.8476713 1 7.144239e-01 # Weight
# Intensity 1.2196050 1 5.388764e-01 # Intensity
# ISO 2.6349405 1 2.090719e-01 # ISO
# SEC 6.0507714 1 2.780045e-02 # SEC
But I'm not happy with the following two issues:
1) How to get rid of the row names?
2) The special characters of #, (, >,) in the column names are not
displayed correctly.
Any suggestions?
Thanks,
Gang
More information about the R-help
mailing list