- https://rogerhilfiker.ch
- @RogerHilfiker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.cookbook-r.com/Manipulating_data/Summarizing_data/ | |
library(tidyverse) | |
id<-1:100 | |
group<-sample(c("Men", "Women"), 100, replace =TRUE) | |
age=rnorm(100, 50, 12) | |
data<-data.frame(id, group, age) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numeric<-sample(c(0,1), 100, replace=TRUE) | |
factor<-factor(numeric, levels=c(0,1), labels=c("nein", "Ja")) | |
mean(numeric) | |
mean(factor) | |
mean(as.numeric(factor)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
# you can find more information here: | |
# https://r4ds.had.co.nz/dates-and-times.html | |
# https://cran.r-project.org/web/packages/lubridate/vignettes/lubridate.html | |
# https://lubridate.tidyverse.org | |
data<-read.table(text="id Tag_Monat_Jahr Monat_Tag_Jahr dmy_hms dob dod date_event date_release_white_album start_rooftop_concert end_rooftop_concert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example to illustrate scientific notation | |
# https://stackoverflow.com/questions/5352099/how-to-disable-scientific-notation | |
scientificNotation=format(c(1000,100,10,1,0.1,0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001), scientific=TRUE) | |
nonScientificNotation=format(c(1000,100,10,1,0.1,0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001), scientific=FALSE) | |
data<-data.frame(nonScientificNotation, scientificNotation) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rio) | |
library(tidyverse) | |
# the two lines with str_replace just show that the author of this code does not know how to correctly format date_time. Sorry for that. | |
st=format(Sys.time(), "%a %b %d %X %Y") | |
st=str_replace_all(st, ":","_") | |
st=str_replace_all(st, " ","_") | |
rio::export(check_error_start_intervention,paste("../02_data_checks/start_intervention_before_eval_initiale",st,".xlsx", sep="_")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rio) | |
library(tidyverse) | |
library(summarytools) | |
size=100000 | |
age_years<-rnorm(size, mean=50, sd=12) | |
gender<-sample(c("1", "2"), size=size,prob=c(0.51, 0.49), replace=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutate(across(Age_mean:woman_perc, as.numeric)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(summarytools) | |
library(dplyr) | |
first_name=c("Hans", "Peter", "", "Fritz", "Susi") | |
family_name=c("Meier", "Muller", "Zgraggen", "", "Zurcher") | |
age=c(43,43,23,55,40) | |
data<-data.frame(first_name, family_name, age) | |
summarytools::freq(data$first_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install.packages("questionr") | |
library(questionr) | |
Thats_a_cool_variable =rnorm(100, 50,12) | |
Thats_a_less_cool_variable =rnorm(100,50,12) | |
Thats_an_even_cooler_variable=rnorm(100,40,21) | |
Does_R_makes_you_angry=rep(0:1,each=50) | |
Does_R_makes_you_happy=rep(c(1,0),each=50) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.brianchildress.co/variables-in-markdown/#:~:text=The%20idea%20is%20pretty%20simple,later%20in%20the%20same%20document. | |
[variable]: 1 |
NewerOlder