# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages
# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats
# For example, here's several helpful packages to load in 

library(ggplot2) # Data visualization
library(readr) # CSV file I/O, e.g. the read_csv function

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

system("ls ../input")
library(data.table)
library(dplyr) 

# Any results you write to the current directory are saved as output.
data = "A,B,C,D\n1,3,5,7\n2,4,6,8\n"

# colClasses    
temp <- fread(data, colClasses=list(character="B"))
fread(data, colClasses=list(character=c("B","C","D")))    # saves typing
fread(data, colClasses=list(character=2:4))     # same using column numbers

dt <- data.table(a = LETTERS[c(1,1:3)], b = 4:7)
dt

dt[.N]
dt[, new_var := .N, by = a]
dt