Message-ID: <1359051817.33112.YahooMailNeo@web142606.mail.bf1.yahoo.com>
Date: 2013-01-24T18:23:37Z
From: arun
Subject: From table to data.frame
In-Reply-To: <CAPFhJgbEjSNYhzGQsSB-3b_4k-rujFb0VZbbVZyXyW0JPav0jA@mail.gmail.com>
Hi,
set.seed(25)
?Z<-rnorm(50,0.5,1)
res<- as.data.frame(table(cut(Z,seq(0,1,by=0.05),labels=seq(0.05,1,by=0.05))) )
?head(res)
?# Var1 Freq
#1 0.05??? 1
#2? 0.1??? 1
#3 0.15??? 0
#4? 0.2??? 0
#5 0.25??? 0
#6? 0.3??? 1
A.K.
----- Original Message -----
From: Wim Kreinen <wkreinen at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Thursday, January 24, 2013 12:39 PM
Subject: [R] From table to data.frame
Hello,
I have a dataframe (test.df) with intervals that were generated by table
(see below). I would prefer a dataframe labeled like this:
> test.tab <- table(cut(skn.test$density, seq (0,1, by=0.05)))
> test.tab
? (0,0.05] (0.05,0.1] (0.1,0.15] (0.15,0.2] (0.2,0.25] (0.25,0.3]
(0.3,0.35]
? ? ? ? 68? ? ? ? 87? ? ? ? 85? ? ? ? 72? ? ? ? 65? ? ? ? 73
74
(0.35,0.4] (0.4,0.45] (0.45,0.5] (0.5,0.55] (0.55,0.6] (0.6,0.65]
(0.65,0.7]
? ? ? ? 72? ? ? ? 77? ? ? ? 78? ? ? ? 75? ? ? ? 74? ? ? ? 83
93
(0.7,0.75] (0.75,0.8] (0.8,0.85] (0.85,0.9] (0.9,0.95]? (0.95,1]
? ? ? ? 89? ? ? ? 75? ? ? ? 67? ? ? ? 59? ? ? ? 56? ? ? ? 208
> test.df <- as.data.frame (test.tab)
> test.df
? ? ? ? Var1 Freq
1? ? (0,0.05]? 68
2? (0.05,0.1]? 87
3? (0.1,0.15]? 85
4? (0.15,0.2]? 72
5? (0.2,0.25]? 65
6? (0.25,0.3]? 73
7? (0.3,0.35]? 74
....
I would prefer a dataframe labelled like this.
0.05? ? 68
0.1? ? ? 87
How to do?
Thanks
Wim
> dput (test.tab)
structure(c(68L, 87L, 85L, 72L, 65L, 73L, 74L, 72L, 77L, 78L,
75L, 74L, 83L, 93L, 89L, 75L, 67L, 59L, 56L, 208L), .Dim = 20L, .Dimnames =
structure(list(
? ? c("(0,0.05]", "(0.05,0.1]", "(0.1,0.15]", "(0.15,0.2]", "(0.2,0.25]",
? ? "(0.25,0.3]", "(0.3,0.35]", "(0.35,0.4]", "(0.4,0.45]", "(0.45,0.5]",
? ? "(0.5,0.55]", "(0.55,0.6]", "(0.6,0.65]", "(0.65,0.7]", "(0.7,0.75]",
? ? "(0.75,0.8]", "(0.8,0.85]", "(0.85,0.9]", "(0.9,0.95]", "(0.95,1]"
? ? )), .Names = ""), class = "table")
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.