What a Code Book should contain 1) information about variables in the data set not contained in the tidy data 2) Information about the summary choices made 3) Information about the experimental study design used
A common format: Word/text file There should be a section called “Study Design” that has a through description of how you collected data.
The instruction list - Ideally in R script - The input is raw data - The output is the processed, tidy data - There are no parameters to the script
Get/set working directory -In Mac OS:
setwd("./data")
-In Windows
setwd("C:\\Users\\Andrew\\Downloads")
Checking for and creating directories
if (!file.exists("data")){
dir.create("data")
}
Getting data from the Internet
download.file(url = , destfile = , )
An example of downloading datat form baltimorecity website
list.files("./data")
[1] "cameras.csv"
How to open local file - I downloaded the Baltimore fixed camera dataset mannually and save it in the file in “./data/Fixed_Speed_Cameras.csv”
Now try to read it!
Some important parameters quote - sometimes we should set quoted="" na.strings - set the character that repressent a missing value nrows - how many rows to read skip - number of lines to skip befere starting to read
read Excel files
library(xlsx)
camrraData2 <- read.xlsx("./data/xxx.xlsx",sheetIndex = 1, header = TRUE)
read.xlxs2 is much faster than read.xlsx but for reading subsets of rows may be slightly unstable
XLConnect package has more options for writing and manipulating Excel files
XLCnonnect cignette is a good place to start for that package
Reading XML
1)Tags, elements and attributes Tages - Start tages - Empty tags<line-break />
Elements - Get the items on the menu and prices
xpathApply(rootNode"//name",xmlValue)
xpathApply(rootNode"//price",xmlValue)
doc <- htmlTreeParse(myUrl, useInternal = TRUE)
Warning: XML content does not seem to be XML: ''
Reading Javascript Object Notation(JSON) - Lightweight data storage
jsonDATA$owner$login
[1] "Zixuan-YU" "Zixuan-YU" "Zixuan-YU" "Zixuan-YU"
Writing data frames to JSON
cat(myjson)
[
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.5,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.9,
"Sepal.Width": 3,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.7,
"Sepal.Width": 3.2,
"Petal.Length": 1.3,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.6,
"Sepal.Width": 3.1,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.6,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.4,
"Sepal.Width": 3.9,
"Petal.Length": 1.7,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 4.6,
"Sepal.Width": 3.4,
"Petal.Length": 1.4,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.4,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.4,
"Sepal.Width": 2.9,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.9,
"Sepal.Width": 3.1,
"Petal.Length": 1.5,
"Petal.Width": 0.1,
"Species": "setosa"
},
{
"Sepal.Length": 5.4,
"Sepal.Width": 3.7,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.8,
"Sepal.Width": 3.4,
"Petal.Length": 1.6,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.8,
"Sepal.Width": 3,
"Petal.Length": 1.4,
"Petal.Width": 0.1,
"Species": "setosa"
},
{
"Sepal.Length": 4.3,
"Sepal.Width": 3,
"Petal.Length": 1.1,
"Petal.Width": 0.1,
"Species": "setosa"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 4,
"Petal.Length": 1.2,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 4.4,
"Petal.Length": 1.5,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 5.4,
"Sepal.Width": 3.9,
"Petal.Length": 1.3,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.5,
"Petal.Length": 1.4,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 3.8,
"Petal.Length": 1.7,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.8,
"Petal.Length": 1.5,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 5.4,
"Sepal.Width": 3.4,
"Petal.Length": 1.7,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.7,
"Petal.Length": 1.5,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 4.6,
"Sepal.Width": 3.6,
"Petal.Length": 1,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.3,
"Petal.Length": 1.7,
"Petal.Width": 0.5,
"Species": "setosa"
},
{
"Sepal.Length": 4.8,
"Sepal.Width": 3.4,
"Petal.Length": 1.9,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3,
"Petal.Length": 1.6,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.4,
"Petal.Length": 1.6,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 5.2,
"Sepal.Width": 3.5,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.2,
"Sepal.Width": 3.4,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.7,
"Sepal.Width": 3.2,
"Petal.Length": 1.6,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.8,
"Sepal.Width": 3.1,
"Petal.Length": 1.6,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.4,
"Sepal.Width": 3.4,
"Petal.Length": 1.5,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 5.2,
"Sepal.Width": 4.1,
"Petal.Length": 1.5,
"Petal.Width": 0.1,
"Species": "setosa"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 4.2,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.9,
"Sepal.Width": 3.1,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.2,
"Petal.Length": 1.2,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 3.5,
"Petal.Length": 1.3,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.9,
"Sepal.Width": 3.6,
"Petal.Length": 1.4,
"Petal.Width": 0.1,
"Species": "setosa"
},
{
"Sepal.Length": 4.4,
"Sepal.Width": 3,
"Petal.Length": 1.3,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.4,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.5,
"Petal.Length": 1.3,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 4.5,
"Sepal.Width": 2.3,
"Petal.Length": 1.3,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 4.4,
"Sepal.Width": 3.2,
"Petal.Length": 1.3,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.5,
"Petal.Length": 1.6,
"Petal.Width": 0.6,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.8,
"Petal.Length": 1.9,
"Petal.Width": 0.4,
"Species": "setosa"
},
{
"Sepal.Length": 4.8,
"Sepal.Width": 3,
"Petal.Length": 1.4,
"Petal.Width": 0.3,
"Species": "setosa"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 3.8,
"Petal.Length": 1.6,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 4.6,
"Sepal.Width": 3.2,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5.3,
"Sepal.Width": 3.7,
"Petal.Length": 1.5,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 5,
"Sepal.Width": 3.3,
"Petal.Length": 1.4,
"Petal.Width": 0.2,
"Species": "setosa"
},
{
"Sepal.Length": 7,
"Sepal.Width": 3.2,
"Petal.Length": 4.7,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 3.2,
"Petal.Length": 4.5,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 6.9,
"Sepal.Width": 3.1,
"Petal.Length": 4.9,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 2.3,
"Petal.Length": 4,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.5,
"Sepal.Width": 2.8,
"Petal.Length": 4.6,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 2.8,
"Petal.Length": 4.5,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 3.3,
"Petal.Length": 4.7,
"Petal.Width": 1.6,
"Species": "versicolor"
},
{
"Sepal.Length": 4.9,
"Sepal.Width": 2.4,
"Petal.Length": 3.3,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 6.6,
"Sepal.Width": 2.9,
"Petal.Length": 4.6,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 5.2,
"Sepal.Width": 2.7,
"Petal.Length": 3.9,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 5,
"Sepal.Width": 2,
"Petal.Length": 3.5,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.9,
"Sepal.Width": 3,
"Petal.Length": 4.2,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 6,
"Sepal.Width": 2.2,
"Petal.Length": 4,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 6.1,
"Sepal.Width": 2.9,
"Petal.Length": 4.7,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 5.6,
"Sepal.Width": 2.9,
"Petal.Length": 3.6,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3.1,
"Petal.Length": 4.4,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 5.6,
"Sepal.Width": 3,
"Petal.Length": 4.5,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 2.7,
"Petal.Length": 4.1,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 6.2,
"Sepal.Width": 2.2,
"Petal.Length": 4.5,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 5.6,
"Sepal.Width": 2.5,
"Petal.Length": 3.9,
"Petal.Width": 1.1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.9,
"Sepal.Width": 3.2,
"Petal.Length": 4.8,
"Petal.Width": 1.8,
"Species": "versicolor"
},
{
"Sepal.Length": 6.1,
"Sepal.Width": 2.8,
"Petal.Length": 4,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 2.5,
"Petal.Length": 4.9,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 6.1,
"Sepal.Width": 2.8,
"Petal.Length": 4.7,
"Petal.Width": 1.2,
"Species": "versicolor"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 2.9,
"Petal.Length": 4.3,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.6,
"Sepal.Width": 3,
"Petal.Length": 4.4,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 6.8,
"Sepal.Width": 2.8,
"Petal.Length": 4.8,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3,
"Petal.Length": 5,
"Petal.Width": 1.7,
"Species": "versicolor"
},
{
"Sepal.Length": 6,
"Sepal.Width": 2.9,
"Petal.Length": 4.5,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 2.6,
"Petal.Length": 3.5,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 2.4,
"Petal.Length": 3.8,
"Petal.Width": 1.1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 2.4,
"Petal.Length": 3.7,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 2.7,
"Petal.Length": 3.9,
"Petal.Width": 1.2,
"Species": "versicolor"
},
{
"Sepal.Length": 6,
"Sepal.Width": 2.7,
"Petal.Length": 5.1,
"Petal.Width": 1.6,
"Species": "versicolor"
},
{
"Sepal.Length": 5.4,
"Sepal.Width": 3,
"Petal.Length": 4.5,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 6,
"Sepal.Width": 3.4,
"Petal.Length": 4.5,
"Petal.Width": 1.6,
"Species": "versicolor"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3.1,
"Petal.Length": 4.7,
"Petal.Width": 1.5,
"Species": "versicolor"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 2.3,
"Petal.Length": 4.4,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 5.6,
"Sepal.Width": 3,
"Petal.Length": 4.1,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 2.5,
"Petal.Length": 4,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 5.5,
"Sepal.Width": 2.6,
"Petal.Length": 4.4,
"Petal.Width": 1.2,
"Species": "versicolor"
},
{
"Sepal.Length": 6.1,
"Sepal.Width": 3,
"Petal.Length": 4.6,
"Petal.Width": 1.4,
"Species": "versicolor"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 2.6,
"Petal.Length": 4,
"Petal.Width": 1.2,
"Species": "versicolor"
},
{
"Sepal.Length": 5,
"Sepal.Width": 2.3,
"Petal.Length": 3.3,
"Petal.Width": 1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.6,
"Sepal.Width": 2.7,
"Petal.Length": 4.2,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 3,
"Petal.Length": 4.2,
"Petal.Width": 1.2,
"Species": "versicolor"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 2.9,
"Petal.Length": 4.2,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.2,
"Sepal.Width": 2.9,
"Petal.Length": 4.3,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 5.1,
"Sepal.Width": 2.5,
"Petal.Length": 3,
"Petal.Width": 1.1,
"Species": "versicolor"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 2.8,
"Petal.Length": 4.1,
"Petal.Width": 1.3,
"Species": "versicolor"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 3.3,
"Petal.Length": 6,
"Petal.Width": 2.5,
"Species": "virginica"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 2.7,
"Petal.Length": 5.1,
"Petal.Width": 1.9,
"Species": "virginica"
},
{
"Sepal.Length": 7.1,
"Sepal.Width": 3,
"Petal.Length": 5.9,
"Petal.Width": 2.1,
"Species": "virginica"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 2.9,
"Petal.Length": 5.6,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.5,
"Sepal.Width": 3,
"Petal.Length": 5.8,
"Petal.Width": 2.2,
"Species": "virginica"
},
{
"Sepal.Length": 7.6,
"Sepal.Width": 3,
"Petal.Length": 6.6,
"Petal.Width": 2.1,
"Species": "virginica"
},
{
"Sepal.Length": 4.9,
"Sepal.Width": 2.5,
"Petal.Length": 4.5,
"Petal.Width": 1.7,
"Species": "virginica"
},
{
"Sepal.Length": 7.3,
"Sepal.Width": 2.9,
"Petal.Length": 6.3,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 2.5,
"Petal.Length": 5.8,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 7.2,
"Sepal.Width": 3.6,
"Petal.Length": 6.1,
"Petal.Width": 2.5,
"Species": "virginica"
},
{
"Sepal.Length": 6.5,
"Sepal.Width": 3.2,
"Petal.Length": 5.1,
"Petal.Width": 2,
"Species": "virginica"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 2.7,
"Petal.Length": 5.3,
"Petal.Width": 1.9,
"Species": "virginica"
},
{
"Sepal.Length": 6.8,
"Sepal.Width": 3,
"Petal.Length": 5.5,
"Petal.Width": 2.1,
"Species": "virginica"
},
{
"Sepal.Length": 5.7,
"Sepal.Width": 2.5,
"Petal.Length": 5,
"Petal.Width": 2,
"Species": "virginica"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 2.8,
"Petal.Length": 5.1,
"Petal.Width": 2.4,
"Species": "virginica"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 3.2,
"Petal.Length": 5.3,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 6.5,
"Sepal.Width": 3,
"Petal.Length": 5.5,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 7.7,
"Sepal.Width": 3.8,
"Petal.Length": 6.7,
"Petal.Width": 2.2,
"Species": "virginica"
},
{
"Sepal.Length": 7.7,
"Sepal.Width": 2.6,
"Petal.Length": 6.9,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 6,
"Sepal.Width": 2.2,
"Petal.Length": 5,
"Petal.Width": 1.5,
"Species": "virginica"
},
{
"Sepal.Length": 6.9,
"Sepal.Width": 3.2,
"Petal.Length": 5.7,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 5.6,
"Sepal.Width": 2.8,
"Petal.Length": 4.9,
"Petal.Width": 2,
"Species": "virginica"
},
{
"Sepal.Length": 7.7,
"Sepal.Width": 2.8,
"Petal.Length": 6.7,
"Petal.Width": 2,
"Species": "virginica"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 2.7,
"Petal.Length": 4.9,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3.3,
"Petal.Length": 5.7,
"Petal.Width": 2.1,
"Species": "virginica"
},
{
"Sepal.Length": 7.2,
"Sepal.Width": 3.2,
"Petal.Length": 6,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.2,
"Sepal.Width": 2.8,
"Petal.Length": 4.8,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.1,
"Sepal.Width": 3,
"Petal.Length": 4.9,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 2.8,
"Petal.Length": 5.6,
"Petal.Width": 2.1,
"Species": "virginica"
},
{
"Sepal.Length": 7.2,
"Sepal.Width": 3,
"Petal.Length": 5.8,
"Petal.Width": 1.6,
"Species": "virginica"
},
{
"Sepal.Length": 7.4,
"Sepal.Width": 2.8,
"Petal.Length": 6.1,
"Petal.Width": 1.9,
"Species": "virginica"
},
{
"Sepal.Length": 7.9,
"Sepal.Width": 3.8,
"Petal.Length": 6.4,
"Petal.Width": 2,
"Species": "virginica"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 2.8,
"Petal.Length": 5.6,
"Petal.Width": 2.2,
"Species": "virginica"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 2.8,
"Petal.Length": 5.1,
"Petal.Width": 1.5,
"Species": "virginica"
},
{
"Sepal.Length": 6.1,
"Sepal.Width": 2.6,
"Petal.Length": 5.6,
"Petal.Width": 1.4,
"Species": "virginica"
},
{
"Sepal.Length": 7.7,
"Sepal.Width": 3,
"Petal.Length": 6.1,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 3.4,
"Petal.Length": 5.6,
"Petal.Width": 2.4,
"Species": "virginica"
},
{
"Sepal.Length": 6.4,
"Sepal.Width": 3.1,
"Petal.Length": 5.5,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6,
"Sepal.Width": 3,
"Petal.Length": 4.8,
"Petal.Width": 1.8,
"Species": "virginica"
},
{
"Sepal.Length": 6.9,
"Sepal.Width": 3.1,
"Petal.Length": 5.4,
"Petal.Width": 2.1,
"Species": "virginica"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3.1,
"Petal.Length": 5.6,
"Petal.Width": 2.4,
"Species": "virginica"
},
{
"Sepal.Length": 6.9,
"Sepal.Width": 3.1,
"Petal.Length": 5.1,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 5.8,
"Sepal.Width": 2.7,
"Petal.Length": 5.1,
"Petal.Width": 1.9,
"Species": "virginica"
},
{
"Sepal.Length": 6.8,
"Sepal.Width": 3.2,
"Petal.Length": 5.9,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3.3,
"Petal.Length": 5.7,
"Petal.Width": 2.5,
"Species": "virginica"
},
{
"Sepal.Length": 6.7,
"Sepal.Width": 3,
"Petal.Length": 5.2,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 6.3,
"Sepal.Width": 2.5,
"Petal.Length": 5,
"Petal.Width": 1.9,
"Species": "virginica"
},
{
"Sepal.Length": 6.5,
"Sepal.Width": 3,
"Petal.Length": 5.2,
"Petal.Width": 2,
"Species": "virginica"
},
{
"Sepal.Length": 6.2,
"Sepal.Width": 3.4,
"Petal.Length": 5.4,
"Petal.Width": 2.3,
"Species": "virginica"
},
{
"Sepal.Length": 5.9,
"Sepal.Width": 3,
"Petal.Length": 5.1,
"Petal.Width": 1.8,
"Species": "virginica"
}
]
Convert back to JSON
More informations about JSON: 1) http://www.json.org/ 2) tutorail: http://www.r-bloggers.com/new-package-jsonlite-a-smarter-json-encoderdecoder/ 3) jsonlite vignette
Data.table 1) written in C and much faster 2) all functions accept data.frame work on data.table
tables()
NAME NROW NCOL MB COLS KEY
1: DT 9 3 0 x,y,z
Total: 0MB
#see all the data tables in memory
subsetting rows
subsetting rows
subsetting columns!! DIFFERENT
k = {print(10); 5}
[1] 10
print(k)
[1] 5
Calculating values for variables with expressions
DT[,table(y)]
y
a b c
3 3 3
Adding new columns, using “:=”
Multiple operations
DT[,m:={tmp <-(x+z); log2(tmp+5)}]
Error in `:=`(m, { :
Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
plyr like operations
Sepcial Variables .N An integer, lenth 1, containing the number
Keys
Joins
Fast Reading
system.time(fread(file))
user system elapsed
0.089 0.016 0.105
system.time(read.table(file, header = TRUE, sep = "\t"))
user system elapsed
5.392 0.110 5.529
the differences with df and dt: https://stackoverflow.com/questions/13618488/what-you-can-do-with-a-data-frame-that-you-cant-with-a-data-table
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.