简体   繁体   中英

Convert data frame to frequency table in R

Using R, I converted a frequency table (created using the table() function) to a data-frame. My data frame now looks as follows:

            words       frequency
1           'home'      1
2           'paper'     5
3           'letter'    6

Now I want to convert this data frame back into a table() object.

How?

You can try this

my.data <- data.frame(words=c("home", "paper", "letter"),
                      frequency=c(1, 5, 6))
my.tbl <- xtabs(frequency ~ words, data=my.data)
is.table(my.tbl) # TRUE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM