0

I've created a frequency table in R with the fdth package using this code

 fdt(x, breaks = "Sturges")

The specific result was:

Class limits         f   rf   rf(%)    cf  cf(%)
 [-15.907,-11.817)   12 0.00  0.10    12   0.10
 [-11.817,-7.7265)    8 0.00  0.07    20   0.16
  [-7.7265,-3.636)    6 0.00  0.05    26   0.21
   [-3.636,0.4545)   70 0.01  0.58    96   0.79
    [0.4545,4.545)   58 0.00  0.48   154   1.27
    [4.545,8.6355)   91 0.01  0.75   245   2.01
   [8.6355,12.726)  311 0.03  2.55   556   4.57
   [12.726,16.817)  648 0.05  5.32  1204   9.89
   [16.817,20.907)  857 0.07  7.04  2061  16.93
   [20.907,24.998) 1136 0.09  9.33  3197  26.26
   [24.998,29.088) 1295 0.11 10.64  4492  36.90
   [29.088,33.179) 1661 0.14 13.64  6153  50.55
   [33.179,37.269) 2146 0.18 17.63  8299  68.18
    [37.269,41.36) 2525 0.21 20.74 10824  88.92
     [41.36,45.45) 1349 0.11 11.08 12173 100.00

It was given as a list:

> class(x)
[1] "fdt.multiple" "fdt"          "list"  

I need to convert it into a data frame object, so I can have a table. How can I do it?

I'm a beginner at using R :(

Valentina
  • 3
  • 2
  • 4
    it will be very difficult for someone to help you. read through [here](https://stackoverflow.com/help/minimal-reproducible-example) to understand how to ask a question that can be answered – Onyambu Nov 17 '20 at 01:57
  • 4
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What columns does the data frame need to have? – MrFlick Nov 17 '20 at 02:00
  • 1
    Can you add the output from `dput(x)`? It provides an unambiguous look at the structure, something that console output (as above) cannot, and it *much* easier for others to quickly try in their console. – r2evans Nov 17 '20 at 02:33

1 Answers1

1

Since you did not provide a reproducible example of your data I have used example from the help page of ?fdt which is closer to what you have.

library(fdth)
mdf <- data.frame(c1=sample(LETTERS[1:3], 1e2, TRUE),
                  c2=as.factor(sample(1:10, 1e2, TRUE)),
                  n1=c(NA, NA, rnorm(96, 10, 1), NA, NA),
                  n2=rnorm(100, 60, 4),
                  n3=rnorm(100, 50, 4),
                  stringsAsFactors=TRUE)
fdt <- fdt(mdf,breaks='FD',by='c1')

class(fdt)
#[1] "fdt.multiple" "fdt"          "list" 

You can extract the table part from each list and bind them together.

result <- purrr::map_df(fdt, `[[`, 'table')
#In base R
#result <- do.call(rbind, lapply(fdt, `[[`, 'table'))
result

#      Class limits  f         rf     rf(%) cf      cf(%)
#1  [8.1781,9.1041)  5 0.20833333 20.833333  5  20.833333
#2   [9.1041,10.03)  6 0.25000000 25.000000 11  45.833333
#3   [10.03,10.956) 10 0.41666667 41.666667 21  87.500000
#4  [10.956,11.882)  3 0.12500000 12.500000 24 100.000000
#5  [53.135,56.121)  4 0.16000000 16.000000  4  16.000000
#6  [56.121,59.107)  8 0.32000000 32.000000 12  48.000000
#7  [59.107,62.092)  8 0.32000000 32.000000 20  80.000000
#....
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213