Skip to content

Instantly share code, notes, and snippets.

View pachevalier's full-sized avatar

Paul-Antoine pachevalier

  • Paris
View GitHub Profile
@pachevalier
pachevalier / gr.R
Last active August 29, 2015 13:56
R markdown, source and graphs
ggplot(data = df, aes(x = x, y = y)) + geom_point()
id variable value x
1 name Mr a -0.966121920990106
2 name Mr b -0.950766916150799
1 name Mr c 0.799965377000893
2 name Mr d 0.956163684921828
@pachevalier
pachevalier / dplyr.R
Last active August 29, 2015 13:56
This program gives the following error message : "R session aborted. R encountered a fatal error. The session was terminated"
library("dplyr")
N <- 100
df <- data.frame(id = 1:N, x = rnorm(N), split = (runif(N) < .5))
df <- group_by(df, split)
groups(df)
summarise(df, x = mean(x2)) # using x2 instead of x
@pachevalier
pachevalier / arrange.R
Last active August 29, 2015 13:57
Problem with the output of arrange
library("dplyr")
set.seed(123)
N <- 100
df <- data.frame(id = 1:N, x = rnorm(N))
df$x[runif(N) < .1] <- NA
table(is.na(tdf$x))
tdf <- tbl_df(df)
out <- arrange(tdf, desc(x))
out2 <- tdf[order(tdf$x, decreasing = TRUE),]
<html>
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://datamaps.github.io/scripts/datamaps.none.min.js"></script>
<div id="container" style="position: relative; width: 500px; height: 300px;"></div>
<script>
[{
"datasetid": "conseils-quartiers",
"recordid": "conseils_quartiers_zip/1",
"fields": {
"shape_area": 0.0,
"objectid": 2,
"area": 903546.02892,
"shape_len": 0.0,
"nar": 18,
"geom_x_y": [48.8981812592, 2.36266859672],
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Var1 Freq label
8441 31 homme
43445 155 femelle
44148 381 mâle
48270 12 Genderqueer
216572 1 Heroes of Might and Magic
251810 1 Féminin
360210 1 Male
746411 1 Ladyboy
1052281 69 femme transgenre
We can make this file beautiful and searchable if this error is corrected: Any value after quoted field isn't allowed in line 1.
"FichierR.D";"InseeNAF";"code.NAF"
"Agriculture, sylviculture et pêche";"A Agriculture, sylviculture et pêche";"A"
"Industrie chimique";"20 Industrie chimique";"C20"
"Fabrication d'autres produits minéraux non métalliques";"23 Fabrication d'autres produits minéraux non métalliques";"C23"
"Édition, audiovisuel et diffusion";"";""
"Toutes branches d'activité";"";""
"Fabrication de produits en caoutchouc et en plastique";"22 Fabrication de produits en caoutchouc et en plastique";"C22"
"Fabrication de machines et équipements non compris ailleurs";"28 Fabrication de machines et équipements n.c.a.";"C28"
"Construction aéronautique et spatiale";"30.3 Construction aéronautique et spatiale";"C30.3"
"Autres industries manufacturières non comprises ailleurs";"32 Autres industries manufacturières";"C32"
library("ggplot2")
set.seed(1234)
N <- 100
df <- data.frame(i = 1:N, x = rnorm(N))
df$y <- 1 + df$x + rnorm(N)
df$z <- (runif(N) < .3)
pdf("output/test.pdf")
ggplot(data = df, aes(x = x, y = y, shape = z)) +
geom_point(size = 3) +