Skip to content

Instantly share code, notes, and snippets.

View sbalci's full-sized avatar
🔬
🔬👀📑🗃📊🏨🗄📇📖⚗📝🎶📈📉📃🖍🔬🔬🏋🏻‍♂🚴🏻‍♂🚙👨‍💻🤷‍♂📸📺🎛🔭🔬💊🔐🍫🌸

Serdar Balcı sbalci

🔬
🔬👀📑🗃📊🏨🗄📇📖⚗📝🎶📈📉📃🖍🔬🔬🏋🏻‍♂🚴🏻‍♂🚙👨‍💻🤷‍♂📸📺🎛🔭🔬💊🔐🍫🌸
View GitHub Profile
@dantalus
dantalus / gist:e181ea23abc6e82239ab
Created January 13, 2015 14:11
Summarize data using R for latex tables
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)
#
@dantalus
dantalus / gist:ea46eed02eb3b8d6f873
Created January 13, 2015 14:16
LaTeX table rows
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) \\
@sbalci
sbalci / SPSSimportRwithVariableLabels.R
Last active April 29, 2018 19:05
SPSS import R with Variable Labels
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
@trinker
trinker / crosstabs with tidyr and dplyr
Created December 18, 2015 22:32
crosstabs with tidyr and dplyr
if (!require("pacman")) install.packages("pacman")
pacman::p_load(dplyr, tidyr, wakefield)
set.seed(10)
dat <- r_data_frame(n = 10000,
race,
age,
sex
)
@aoles
aoles / bash.Rmd
Created October 8, 2018 10:09
Save bash code chunks in R Markdown documents into separate script files
---
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)
@seasmith
seasmith / keyword-vector-subsetting.R
Created July 18, 2019 16:44
Intuitive vector subsetting using keywords
`[.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"))
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')
@summerofgeorge
summerofgeorge / rename-jpg-files.r
Last active October 29, 2019 10:08
Rename all jpg files in a folder
# 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
@CGMossa
CGMossa / .Rprofile
Last active February 11, 2020 17:34
#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")
@DarwinAwardWinner
DarwinAwardWinner / .Rprofile
Created January 11, 2020 17:32
The environment setup for my R profile
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")