Jane Sully
Jane Sully

Reputation: 3347

How to format dplyr output in R into doubles (or other workable format)?

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)

Upvotes: 1

Views: 105

Answers (1)

ka0
ka0

Reputation: 108

coerce it to a dataframe.

prop_smoking <- as.data.frame(prop_smoking)

Upvotes: 1

Related Questions