开发者

Inserting factor values into an R matrix

I have a matrix of the form

arkhansas 15 16 17
newyork 56 45 30

where column 1 are factors and columns开发者_StackOverflow社区 2:4 are integers.

I'm stuck trying to generate a matrix with the form:

15 arkhansas 1
16 arkhansas 2
17 arkhansas 3
56 newyork 1
45 newyork 2
30 newyork 3

Every time I try to assign the factor value to the second column of my new matrix I get numbers instead of city names, how can I solve that?


as.character() will coerce your factor into a character string like you want.

That said, providing example code would be helpful. Try using dput() on your matrix object and copying and pasting the results into your post. You're likely using a data.frame not a matrix, since I believe matrices can only hold one data type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜