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 25 python 20 fuzzy 13 hugo_cms 11 azure-ml 10 linear-regression 10 gradient-descent 9 type2-fuzzy 7 type2-fuzzy-library 7 type1-fuzzy 5 cnc 4 dataset 4 datastore 4 excel 3 it2fs 3 r 3 c 2 c-sharp 2 experiment 2 iot 2 paper-workout 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 hyperparameter-tuning 1 javascript 1 learning 1 mathjax 1 maths 1 model-optimization 1 mxchip 1 pandas 1 pipeline 1 random_walk 1 roc 1 tools 1 vscode 1 wsl 1