The R Notes - Part 3

Sat February 8, 2020
r

Reading and Writing Data

Reading tabular data - read.table & read.csv. there return a DataFrame. Equivalent for writing is write.table

read.table(
file, 
header = FALSE,                                  # has separator
sep = "",                                        # seperator example ","default is space
quote = "\"'",
dec = ".", 
numerals = c("allow.loss", "warn.loss", "no.loss"),
row.names, 
col.names, 
as.is = !stringsAsFactors,
na.strings = "NA", 
colClasses = NA,                                 # character vector indicating the class
                                                 # of each vector. not required
nrows = -1,                                      # number of rows. not required
skip = 0,                                        # skip from beginneing
check.names = TRUE, 
fill = !blank.lines.skip,
strip.white = FALSE, 
blank.lines.skip = TRUE,
comment.char = "#",                              # comment symbol. anything to the right is                                                   ignored
allowEscapes = FALSE, 
flush = FALSE,
stringsAsFactors = default.stringsAsFactors(),   # encode character variables as factors
fileEncoding = "", 
encoding = "unknown", 
text, 
skipNul = FALSE)

Consider the following data file:

Name, Surname, Age, Rating, Senior
Mark, Brown, 40, 1, TRUE
Colin, Smith, 41, 1, TRUE
Joe, Blogs, 27, 2, FALSE
#Joe2, Blogs, 27, 2, FALSE

Use the following to read,

data<-read.table("info.txt",header = TRUE, 
sep="," , 
colClasses = c("character", "character", "integer",                 "integer", 
"logical")

print(data)
Name   Surname Age Rating Senior
1      Mark      Brown  40      1   TRUE
2     Colin     Smith  41      1   TRUE
3     Joe  Blogs  27      2  FALSE

When Separator is “,” you can use read.csv. Header is always equal to TRUE

ReadLines reads any file and returns a character vector. Equivalent for writing is WriteLines

Source will read R code, also dget. Equivalent for writing is Dump and dput

load & unserialize will read binary objects. Equivalent for writing is save & serialize




The R Notes - Part 2

February 8, 2020
r

The R Notes - Part 1

February 8, 2020
r
comments powered by Disqus


machine-learning 27 python 21 fuzzy 14 azure-ml 11 hugo_cms 11 linear-regression 10 gradient-descent 9 type2-fuzzy 8 type2-fuzzy-library 8 type1-fuzzy 5 cnc 4 dataset 4 datastore 4 it2fs 4 excel 3 paper-workout 3 r 3 c 2 c-sharp 2 experiment 2 hyperparameter-tuning 2 iot 2 model-optimization 2 programming 2 robotics 2 weiszfeld_algorithm 2 arduino 1 automl 1 classifier 1 computation 1 cost-functions 1 development 1 embedded 1 fuzzy-logic 1 game 1 javascript 1 learning 1 mathjax 1 maths 1 mxchip 1 pandas 1 pipeline 1 random_walk 1 roc 1 tools 1 vscode 1 wsl 1