Skip to content
Prev 377688 / 398502 Next

how to keep colnames of matrix when put it into a data frame

Your names are not syntactically valid.

Consider:
a b c
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
x a b c
1 1 1 4 7
2 2 2 5 8
3 3 3 6 9

See ?make.names, and the "Value" section of ?data.frame for how names are
constructed.

Michael's suggestion produces a matrix, not  a data frame. dimnames of
matrices apparently have different rules for validity.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sun, Dec 9, 2018 at 7:05 AM Jinsong Zhao <jszhao at yeah.net> wrote: