R Notes

https://cran.r-project.org/doc/manuals/R-intro.pdf

Case sensitive

Database connectivity

http://www.ibm.com/developerworks/data/library/techarticle/dm-1402db2andr/

Install packages on locked down installation:

.libPaths(c(“C:\\Users\\lross\\R\\library”, .libPaths()))

Manually unzip required packages into above path, then you can use as normal

e.g. library(openxlsx)

alternate: library(ggplot2, lib.loc=”/data/Rpackages/”)

Unload package:

detach(package:openxlsx)

Clear workspace (Default action at start of a file?)

rm(list=ls())

Merging Data
Adding Columns
To merge two data frames (datasets) horizontally, use the merge function. In most cases, you join two data frames by one or more common key variables (i.e., an inner join).

# merge two data frames by ID
total <- merge(data frameA,data frameB,by=”ID”)

# merge two data frames by ID and Country
total <- merge(data frameA,data frameB,by=c(“ID”,”Country”))

Add column to Data Frame

Add column to dataframe, combined with vector (row) operation

mtcars1 <- mtcars
mtcars1$x <- mtcars1$gear * mtcars1$carb
mtcars1

xx

 

 

Posted in R