try also
m <- matrix( runif(5^2), nrow=5, dimnames = Names<- list(
c("A","B","C","D","E"),
c("O","P","Q","R","S") ) )
data.frame(expand.grid(Names[[1]],Names[[2]]),as.numeric(m))
data.frame(code=outer(Names[[1]],Names[[2]],paste,sep=".")[1:25],num=as.numeric(m))
Patrizio
2009/3/25 jim holtma
Use the 'reshape' package:
> library(reshape)
> melt(m)
X1 X2 value
1 A O 0.26550866
2 B O 0.37212390
3 C O 0.57285336
4 D O 0.90820779
5 E O 0.20168193
6 A P 0.89838968
7 B P 0.94467527
8 C P 0.66079779
9 D P 0.62911404
10 E P 0.06178627
11 A Q 0.20597457
12
G'day Ken,
On Wed, 25 Mar 2009 00:13:48 -0700 (PDT)
Ken-JP wrote:
>
> Say I have:
>
> > set.seed( 1 )
> > m <- matrix( runif(5^2), nrow=5, dimnames =
> > list( c("A","B","C","D","E"), c("O","P","Q","R","S") ) )
> > m
> O P Q R S
> A 0.2655087 0.898389
try this:
set.seed(1)
m <- matrix(runif(5^2), nrow = 5,
dimnames = list(c("A","B","C","D","E"), c("O","P","Q","R","S")))
v <- c(m)
names(v) <- paste(rownames(m), colnames(m)[col(m)], sep = ".")
# or
# names(v) <- outer(rownames(m), colnames(m), paste, sep = ".")
v
I hope it helps.
Best,
D
Say I have:
> set.seed( 1 )
> m <- matrix( runif(5^2), nrow=5, dimnames = list( c("A","B","C","D","E"),
> c("O","P","Q","R","S") ) )
> m
O P Q R S
A 0.2655087 0.89838968 0.2059746 0.4976992 0.9347052
B 0.3721239 0.94467527 0.1765568 0.7176185 0.2121425
C
5 matches
Mail list logo