[R] From table to data.frame

Rui Barradas ruipbarradas at sapo.pt
Thu Jan 24 19:37:48 CET 2013


Hello,

try the following.

test.df$Var1 <- seq(0,1, by=0.05)[-1]
test.df


Hope this helps,

Rui Barradas

Em 24-01-2013 17:39, Wim Kreinen escreveu:
> 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.
>



More information about the R-help mailing list