06-R-stuff


R in Jupyter

install conda environment via the src/install.bash script in this repo


In [1]:
library(dplyr)
library(ggplot2)


Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union


In [2]:
head(economics)


Out[2]:
datepcepoppsavertuempmedunemploy
11967-06-30507.81987129.84.52944
21967-07-31510.91989119.84.72945
31967-08-31516.719911394.62958
41967-09-30513.31993119.84.93143
51967-10-31518.51994989.74.73066
61967-11-30526.21996579.44.83018

In [3]:
a <- ggplot(data = economics, aes(x = date, y = unemploy))
a <- a + geom_line()
a



In [4]:
a <- ggplot(data = economics, aes(x = date, y = unemploy))
a <- a + geom_line()
a <- a + geom_smooth(method = "loess")
a



In [5]:
df <- data.frame(birth_state=c("Illinois", "Arizona", NA),
                 data_scientist=c("Kevin", "Matt", "Jonathan"))

In [6]:
df


Out[6]:
birth_statedata_scientist
1IllinoisKevin
2ArizonaMatt
3NAJonathan

In [7]:
df$birth_state == "Arizona"


Out[7]:
  1. FALSE
  2. TRUE
  3. NA

In [8]:
just_Arizona <- df[df$birth_state=="Arizona",]

In [9]:
just_Arizona


Out[9]:
birth_statedata_scientist
2ArizonaMatt
NANANA

In [10]:
really_just_Arizona <- df[which(df$birth_state=="Arizona"),]

In [11]:
really_just_Arizona


Out[11]:
birth_statedata_scientist
2ArizonaMatt

In [ ]: