Skip to content

Instantly share code, notes, and snippets.

View andrewbtran's full-sized avatar

Andrew Tran andrewbtran

View GitHub Profile
from __future__ import unicode_literals
import requests
import json
import time
import codecs
import sys
UTF8Writer = codecs.getwriter('utf8')
sys.stdout = UTF8Writer(sys.stdout)
library(dplyr)
ctmeet <- read.csv("meetup_groups.csv", quote = "",
row.names = NULL,
stringsAsFactors = FALSE)
# Adding column names
colnames(ctmeet) <- c("Area","Group","Created","Neighborhood","State","Category","Members","Who")
# Converting the Date group was created into a recognized format
@andrewbtran
andrewbtran / gist:a3892869448130c7dda0
Created June 12, 2015 00:45
build a dataframe in r
teams <- c(“Patriots”,”Red Sox”,”Celtics”)
losses <- c(5,13,21)
away <- c(TRUE,FALSE,TRUE)
sports <- data.frame(teams,losses,away)
@andrewbtran
andrewbtran / setdirectoryr
Created June 12, 2015 00:51
set directory in r
# Example for a Mac
setwd(“~/Downloads”)
# Example for a PC
setwd(“C:/User/Downloads”)
@andrewbtran
andrewbtran / readincsv
Last active August 29, 2015 14:22
read in CSV file, assign it to a variable
# read in CSV file, assign it to a variable
earnings <- read.csv("Employee_Earnings_Report_2014.csv", stringsAsFactors=FALSE)
# Why the stringsAsFactors=FALSE? Because you're telling to interpret the text in the spreadsheet as a String, not a Factor
# Why is R obsessed with Factors? Blame statisticians.
@andrewbtran
andrewbtran / nrow
Created June 12, 2015 01:03
how many rows in R?
# How many rows?
nrow(earnings)
@andrewbtran
andrewbtran / firstfivelastfive
Created June 12, 2015 01:05
head and foot in R
# Look at the first five rows in the Console
head(earnings)
# Alternatively, to look at the last five rows
foot(earnings
@andrewbtran
andrewbtran / str
Created June 12, 2015 01:12
structure r
# Investigate the structure of the dataframe
str(earnings)
@andrewbtran
andrewbtran / numeric
Created June 12, 2015 01:22
change to numeric format r
#Change column to number format (first you have to strip out the $)
#The $ is a special character
earnings$TOTAL.EARNINGS <- gsub("\\$", "", earnings$TOTAL.EARNINGS)
#Function to change the format to numeric
earnings$TOTAL.EARNINGS <- as.numeric(earnings$TOTAL.EARNINGS)