![]() Group<-sort(rep(seq(1,ceiling(n/step)),step)) The present version incorporates useful comments by pat and ap53! ![]() The function takes three parameters: the R object on which we need to obtain statistics (x), how many entries should each summary contain (step, defaulting to 1000), and the function we want to apply (fun, defaulting to “mean”). To show the order, we can pipe the output into a command called tabyl(), from the janitor package, which is a tidyverse friendly version of table().I imagine that the same result can be achieved by a proper use of quantile, but I like to have an easy way to obtain summary statistics every n entries of my dataset be it a vector or ame. ![]() Remember when we wanted to decide the order of the categories in the factor? We can assign that order using the levels argument in factor(). We’re taking the previous values of our variable ( gender), doing something to it (making it a factor), and then reassigning the variable gender to our fixed set of values. One thing to notice: we are doing something called reassignment here. # $ gender male, male, female, male, female, male. Smoke_complete %>% #reassign the gender variable to be a factor mutate( gender = factor(gender)) %>% glimpse() # Rows: 1,152 # $ ethnicity "not hispanic or latino", "not hispanic. # $ gender "male", "male", "female", "male", "fema. # $ years_smoked NA, NA, NA, NA, NA, NA, NA, NA, NA, 26. # $ vital_status "dead", "dead", "dead", "alive", "alive. # $ tumor_stage "stage ia", "stage ib", "stage ib", "st. Smoke_complete %>% mutate( age_at_death = age_at_diagnosis + days_to_death) %>% glimpse() # Rows: 1,152 8.8.2 More about the Multiple Testing Problem.8.8 Analysis of Variance (ANOVA) (Optional).8.6 How Correlated are the Three Variables?.8.2.2 Googling is StandaRd pRactice foR eRrors.8.2.1 Understanding the difference between warnings and errors.7.5 Making your data long: pivot_longer().7 Part 5: Doing useful things with multiple tables.6.8 Other really useful forcats functions.6.5 fct_rev() - reversing the order of a factor.6.1 Making a factor variable out of disease.5.5 Standardizing variable names: clean_names().5.4.3 group_by()/summarize to calculate mean and standard deviation values.5.3.4 Using mutate to make a continuous variable categorical using case_when.5.3.3 Using mutate to make our character variables into factors.5.3.1 Using mutate to calculate a new variable based on other variables.5.3 mutate() - A confusing name, a powerful dplyr verb.5 Part 4: mutate(), group_by()/summarize().4.7.8 The difference between filter() and select(). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |