Skip to content

Instantly share code, notes, and snippets.

View chendaniely's full-sized avatar

Daniel Chen chendaniely

View GitHub Profile
@chendaniely
chendaniely / Facet by Continents
Last active August 29, 2015 14:15
SWC Plot This Post
library(stringr)
library(plyr)
library(ggplot2)
parse_row <- function(row_values){
keep <- row_values[1]
keep <- as.character(keep)
split_keep <- str_split_fixed(string = keep, pattern = ' ', n = 5)
continent_code <- split_keep[1]
country_code_2 <- split_keep[2]
@chendaniely
chendaniely / plot_edge_list.R
Created April 23, 2015 15:31
Plot a recurrent artificial neural network using igraph and base graphics
library(igraph)
# get my dataset from the structure.R file
source('structure.R')
# create graph from edgelist
# note it has to be a matrix, not a dataframe
g <- graph.edgelist(as.matrix(edge_list_values[, names(edge_list_values) %in%
c("j_name", "i_name")]))
g
@chendaniely
chendaniely / pandas_cols_multi_variable.ipynb
Created February 4, 2018 18:43
Columns containing multiple bits of information
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chendaniely
chendaniely / pandas_replace.ipynb
Last active March 28, 2018 21:26
Pandas replacing values
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chendaniely
chendaniely / predict_type.md
Created June 19, 2019 01:55
predict type='terms'
title output editor_options
Predict type = 'terms'
html_document
keep_md toc
true
true
chunk_output_type
console
@chendaniely
chendaniely / bined_counts_over_regplot.ipynb
Last active June 11, 2020 17:42
fitted (smooth) line that also shows the distribution of the data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chendaniely
chendaniely / altair_test.Rmd
Last active December 4, 2020 17:03
Altair in Rmd
---
title: "rmd altair"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(reticulate)
@chendaniely
chendaniely / index.Rmd
Created January 11, 2021 02:27
backup caption post
---
# Documentation: https://sourcethemes.com/academic/docs/managing-content/
title: "Creating and Adding Subtitles to Your Videos"
subtitle: ""
summary: ""
authors: []
tags: []
categories: []
date: 2020-08-27T19:51:05-05:00
@chendaniely
chendaniely / chained_indexing-base_tidyverse.R
Last active October 15, 2021 16:27
R Copy on write/change example
# base R -----
mycars <- mtcars
mycars
# mpg cyl disp hp drat wt qsec vs am gear carb
# Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
# Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
# Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
# Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
@chendaniely
chendaniely / inplace_example.py
Last active January 15, 2022 19:53
Pandas assign inplace example
# tl;dr: you can't assign in place because inplace returns None
import pandas as pd
dat = pd.util.testing.makeMixedDataFrame()
print(dat)
# A B C D
# 0 0.0 0.0 foo1 2009-01-01
# 1 1.0 1.0 foo2 2009-01-02
# 2 2.0 0.0 foo3 2009-01-05