- https://rogerhilfiker.ch
- https://orcid.org/0000-0001-8662-6116
- @RogerHilfiker
- in/roger-hilfiker-59075b39
This file contains hidden or 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(dplyr) | |
| # see https://www.tidyverse.org/blog/2020/04/dplyr-1-0-0-colwise/ | |
| # see https://vbaliga.github.io/replace-text-in-specific-column/ | |
| ID<-1:3 | |
| Names<-c("Peter", "Paul", "Marhy") | |
| FamilyNames<-c("Lennon", "McCartney", "Jagger") | |
| Age<-rnorm(3, 80, 12) | |
| data<-data.frame(Names, FamilyNames, ID, Age) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) | |
| # thanks for the help: | |
| # https://community.rstudio.com/t/pivot-longer-on-multiple-column-sets-pairs/43958/9 | |
| # https://cran.r-project.org/web/packages/stringr/vignettes/regular-expressions.html | |
| walking_speed_1<-c(0.3,0.5,0.7) | |
| balance_four_balance_test_1<-c(1,2,1) | |
| tug_1<-c(10,20,12) | |
| walking_speed_2<-c(0.4,0.6,0.8) |
This file contains hidden or 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 hidden or 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) |
NewerOlder