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
summaryA <- function(data, ...){ | |
# Example | |
# | |
# data <- data.frame("A" = rnorm(500, 0, 1), | |
# "B" = rnorm(500, 0, 1), | |
# "C" = factor(sample(c("Ca", "Cb"), 500, replace = T))) | |
# | |
# a <- summaryA(data) | |
# |
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
Sex & 3 & & & & \\ | |
\multicolumn{1}{r}{Male} & & 51\% & 50\% & 60\% \\ | |
\multicolumn{1}{r}{Female} & & 49\% & 50\% & 40\% \\ | |
Gestational Age (wks) & 0 & 40.3(39.3 to 41) & 40.3(39.3 to 41) & 40.1(39.4 to 41) \\ | |
Birth weight (g) & 3 & 3460(3150 to 3770) & 3430(3120 to 3720) & 4390(4065 to 4605) \\ | |
Birth length (cm) & 71 & 50.2(49 to 51.8) & 50(48.9 to 51.5) & 53(51.5 to 54) \\ | |
Fat mass (\%) & 531 & 10.9(8.2 to 13.8) & 10.6(8 to 13.4) & 16(13.1 to 18.5) \\ | |
Age (yrs) & 0 & 30(28 to 33) & 30(28 to 33) & 31(28 to 33) \\ | |
Height (cm) & 0 & 165(161 to 168) & 165(161 to 168) & 165(160.2 to 169) \\ | |
Weight (kg) & 0 & 65(59.2 to 74) & 65(60 to 74) & 65(58 to 75.8) \\ |
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(foreign) # foreign paketi yükleniyor | |
# read.spss komutu ile değer etiketlerini almasını ve bunu liste olarak değil de data.frame olarak kaydetmesini istiyoruz | |
mydata <- read.spss("mydata.sav", use.value.labels = TRUE, to.data.frame = TRUE) | |
# aktardığımız data.frame'in özellikleri (attr) içinde değişkenlerin etiketleri var, bunları dışarı çıkartıyoruz | |
VariableLabels <- as.data.frame(attr(mydata, "variable.labels")) | |
# elde ettiğimiz data.frame'deki satır isimleri değişkenlerin isimleri oluyor, karşılarında da değişken etiketleri var | |
# satır isimlerini de dışarı çıkartıyoruz |
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
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(dplyr, tidyr, wakefield) | |
set.seed(10) | |
dat <- r_data_frame(n = 10000, | |
race, | |
age, | |
sex | |
) |
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
--- | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knit_hooks_source <- knitr::knit_hooks$get("source") | |
knitr::knit_hooks$set(source = function (x, options) { | |
if (!is.null(options$save)) | |
writeLines(x, options$save) | |
knit_hooks_source(x, options) |
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
`[.hmmm` <- function (x, i, ...) { | |
isub <- substitute(i) | |
is_seq <- identical(as.list(isub)[[1L]], as.name(":")) | |
if (is_seq) { | |
end_seq <- as.list(isub)[[3L]] | |
is_end <- identical(end_seq, as.name("end")) |
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(gganimate) # thomasp85/gganimate | |
library(cartogram) | |
library(geogrid) # Need github version jbaileyh/geogrid | |
library(rnaturalearth) | |
library(sf) | |
library(scico) | |
us <- ne_states('united states of america', returnclass = 'sf') | |
us <- us[!us$woe_name %in% c('Alaska', 'Hawaii'), ] | |
us <- st_transform(us, '+proj=eqdc +lat_0=39 +lon_0=-96 +lat_1=33 +lat_2=45 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs') |
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
# List the jpg files in the folder | |
old_files <- list.files("C:/ImageTest", pattern = "*.JPG", full.names = TRUE) | |
old_files | |
# Create vector of new files | |
new_files <- paste0("C:/NewFiles/file_",1:length(old_files),".JPG") | |
new_files |
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
#TODO: Find a way to restart R without using this particular .Rprofile. | |
# | |
# CLEAN_SESSION <- TRUE | |
CLEAN_SESSION <- FALSE | |
if (interactive() && !CLEAN_SESSION) { | |
# Configure session ------------------------------------------------------- | |
message("Interactive mode configuration") |
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
local({ | |
## Put everything in a separate environment and attach that | |
## environment. Re-use the existing one from the search path it | |
## it's available, so that re-executing this file doesn't add a | |
## new environment to the search path every time. | |
custom_env <- tryCatch(as.environment("rct_custom_env"), | |
error=function(...) { | |
attach(NULL, name="rct_custom_env") | |
as.environment("rct_custom_env") |
OlderNewer