[R] dataframe transposition
Jan.Schelling@hydro.com
Jan.Schelling at hydro.com
Wed Oct 13 09:55:04 CEST 1999
you could try:
cnames <- levels(wk$authorisor)
rnames <- names(wk)[-1]
wk <- data.frame(t(wk[,-1]))
names(wk) <- cnames
row.names(wk) <- rnames
to check the structure of the object I would recommend str() instead of page():
str(wk)
Jan Schelling
-
Norsk Hydro
Research Centre
N - 3907 Porsgrunn
jan.schelling at hydro.com
-
----------------------
mlapsley at ndirect.co.uk on 99-10-13 12:21 AM GMT
Dear R-helpers,
I wonder if I could impose upon you for forther assistance, this
time with dataframes: hopefully this will be of general interest,
as I personally have found them hard to get to grips with.
I was trying to transpose rows and cols and move col1 to the names.
Then all sorts of things go wrong. Although the end result looks
the same, page() shows the structure to be quite different compared
to building it by hand.
What is going on? And how am I supposed to do this. (And no,
I didn't expect that the output of plot() would be sensible!)
Thanks again,
Michael
> wk
authorisor count(*)
1 JMC 4
2 LCA 259
3 MCM 136
4 MDH 266
5 ML 27
6 SA 1
>
>page(wk)
structure(list(authorisor = c("JMC", "LCA", "MCM", "MDH", "ML",
"SA"), "count(*)" = c("4", "259", "136", "266", "27", "1")),
.Names =c("authorisor",
"count(*)"), row.names = c("1", "2", "3", "4", "5", "6"), class = "data.frame")
>wk[,1]->dnames
>as.data.frame(t(wk))->wk
>wk[-1,]->wk
>names(wk)<-dnames
>wk
JMC LCA MCM MDH ML SA
count(*) 4 259 136 266 27 1
> plot(wk)
Error: non-numeric data type in frame
>
>page(wk3)
structure(list(JMC = structure("4 ", .Names = "count(*)"), LCA =
structure("259", .Names = "count(*)"),
MCM = structure("136", .Names = "count(*)"), MDH = structure("266",
.Names= "count(*)"),
ML = structure("27 ", .Names = "count(*)"), SA = structure("1 ", .Names =
"count(*)")), .Names = c("JMC",
"LCA", "MCM", "MDH", "ML", "SA"), row.names = "count(*)", class = "data.frame")
rbindnd(c(4,259,136,266,27,1))->wk2
> as.data.frame(rbind(c(4,259,136,266,27,1)))->wk2
> names(wk2)<-dnames
> wk2
JMC LCA MCM MDH ML SA
1 4 259 136 266 27 1
> page (wk2)
structure(list(JMC = 4, LCA = 259, MCM = 136, MDH = 266, ML = 27,
SA = 1), .Names = c("JMC", "LCA", "MCM", "MDH", "ML", "SA"
), row.names = "1", class = "data.frame")
>
----------------------------------
E-Mail: Michael Lapsley <mlapsley at ndirect.co.uk>
Date: 13-Oct-99
Time: 01:12:23
This message was sent by XFMail
----------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list