[R] data.frame handling

Michela Cameletti michela.cameletti at unibg.it
Mon Mar 19 23:46:20 CET 2007


Dear R-users,
I have a little problem that I can't solve by myself.
I have a data frame with 2 factors and 8 observations (see the following
code):

 y <- c(1,1,1,2,2,3,3,3)
 y <- factor(y)
 levels(y) <- c("a","b","c")
 x <- c(1,2,3,1,2,1,2,3)
 x <- factor(x)
 levels(x) <- c("x","y","z")
 X  <- data.frame(factor1=x,factor2=y)

and the final result is

  factor1 factor2
1       x       a
2       y       a
3       z       a
4       x       b
5       y       b
6       x       c
7       y       c
8       z       c

>From the above data I'd like to obtain the following matrix:
	a	b	c
x	1	1	1
y	1	1	1
z	1	0	1

Do you have any advice? Can you help me please?
Thank you in advance,
Michela



More information about the R-help mailing list