1

How do I get the outcome of this to be numerical values versus tibbles.

prop_smoking <- df %>% 
    group_by(Age) %>%
    summarise(ratio = sum(Smoking == 'yes')/n()) 

This gives me output like this:

Age     Ratio
18-24  .134
25-35  .144
36-50  .189

I want to add each value to its corresponding vector because I am using a resampling approach. However, if I index in the following way: prop_smoking[1,2] it gives me a tibble type. Therefore, when I add it to its corresponding vector and want to do things like loop through and subtract the mean as I would with a vector, I get a "non-numeric argument to binary operator". How can I index or convert the values so they are easy to work with (i.e. doubles)

neilfws
  • 32,751
  • 5
  • 50
  • 63
Jane Sully
  • 3,137
  • 10
  • 48
  • 87
  • Including a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) in your question will increase your chances of getting an answer. – Samuel Oct 20 '17 at 01:30
  • 2
    `as.numeric(prop_smoking[1,2])` ? – Remko Duursma Oct 20 '17 at 01:40

1 Answers1

1

coerce it to a dataframe.

prop_smoking <- as.data.frame(prop_smoking)
ka0
  • 108
  • 7