[R] How to built a pivot table of value
CE.KA
ce.kaya75 at yahoo.fr
Sat Dec 1 13:37:02 CET 2012
Hi R users
Imagine the table "base":
p=c("d","d","b","b","a","a")
q=c("v1","v2","v1","v2","v1","v2")
r=c(5,2,4,8,9,7)
base=data.frame(p,q,r)
base
p q r
1 d v1 5
2 d v2 2
3 b v1 4
4 b v2 8
5 a v1 9
6 a v2 7
How programming R to get this result:
v1 v2
a 9 7
b 4 8
d 5 2
I tried the function table but the result is divided in several matrix:
table(base$p,base$q,base$r)
, , = 2
v1 v2
a 0 0
b 0 0
d 0 1
, , = 4
v1 v2
a 0 0
b 1 0
d 0 0
, , = 5
v1 v2
a 0 0
b 0 0
d 1 0
, , = 7
v1 v2
a 0 1
b 0 0
d 0 0
, , = 8
v1 v2
a 0 0
b 0 1
d 0 0
, , = 9
v1 v2
a 1 0
b 0 0
d 0 0
SIncerely yours
--
View this message in context: http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list