0

I'm trying to create a table that documents the number of times a type of book is mentioned in my data set. This is what I've tried:

my_table <- table(library$Title)

Now I've been looking online and found a couple sites that are helpful, such as this one. They have this example:

is.na(clinical.trial$age) <- sample(1:100, 20)
summary(clinical.trial)

#    patient            age            treatment       center
# Min.   :  1.00   Min.   :46.61   Treatment:50   Center A:22
# 1st Qu.: 25.75   1st Qu.:56.19   Control  :50   Center B:10
# Median : 50.50   Median :60.59                  Center C:28
# Mean   : 50.50   Mean   :60.57                  Center D:23
# 3rd Qu.: 75.25   3rd Qu.:64.84                  Center E:17
# Max.   :100.00   Max.   :77.83
#                  NA's   :20.00    

table(clinical.trial$center)

# Center A Center B Center C Center D Center E
# 22       10       28       23       17  

That's along the lines of what I want, however I simply have a column with book titles in my csv document that the program is calling.

For example: Cosmos, The Hobbit, The Story of Light, and The Great Gatsby are mentioned and the printed result simply says "26, 30, 22, 35". Not only are they not labeled, I also don't know which value goes with what.

If this information helps, I'm writing the code in an R Markdown file, knitting it and results pop up in a separate html file.

What do I need to do in order to have the book title match with the number of times they are mentioned?

Kevin Arseneau
  • 6,186
  • 1
  • 21
  • 40
matryoshka
  • 135
  • 8
  • 1
    Side note (I'm curious): you used "snippet" in your question, but it contains neither the data nor indications of how to get the snippet code to function (e.g., which language to use, proper pure-R code). Does this methodology work in other programming languages within StackExchange and/or StackOverflow? – r2evans Jan 21 '18 at 00:27
  • 2
    This is difficult to help with details since your question is not [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). For instance, you mention books and titles, but nowhere can we see the structure or contents of `library` (bad variable name, btw), so it's difficult to give you something meaningful. – r2evans Jan 21 '18 at 00:30

1 Answers1

1

I've always resorted to the hack of using as.matrix around a table when I want the columns to be "downgoing" instead of "horizontal":

> tbl <- table( sample(letters[1:10], 30, repl=TRUE))
> tbl

a b c d e f g h i j 
4 3 2 3 2 2 2 3 1 8 
> as.matrix(tbl)
  [,1]
a    4
b    3
c    2
d    3
e    2
f    2
g    2
h    3
i    1
j    8
IRTFM
  • 258,963
  • 21
  • 364
  • 487