Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 29 pages
Summary

Data Mining - Practical Summary

Document preview thumbnail
Preview 3 out of 29 pages

Practicum notes for Data Mining at Universiteit Antwerpen covering R fundamentals and data handling. Topics include working directories, reading/writing tables from Excel and text files, data types (numeric, character, factor, logical), and data structures (vectors, matrices, data frames, lists). Essential for passing the practical part of the course.

Content preview

Practicum 1: The Basics
The working directory
❥ Using this command you can ask R where its working directory is: getwd()
❥ If you want to change the working directory you can use this command: setwd(“c:\temp\...”)
❣ Note that this needs to be changed accordingly
❣ Note also that R doesn’t recognize “\” but only “/” so change this also
❥ You can then ask R to list all files in the working directory and determine which files can be read and
which can’t: list.files(getwd())

Working with tables in excel and text format
❥ Read a table in an excel or text file
❣ You can ask R to read a table in an excel or text file using this command:
read.table(“filename.filetype”)
❣ Further specifications on how R should interpret different aspects can be given
⤷ read.table(file, header = FALSE, sep = "", quote = "\"'", dec = ".",
row.names, col.names, as.is = !stringsAsFactors, na.strings = "NA",
colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill =
!blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE,
comment.char = "#", allowEscapes = FALSE, flush = FALSE, stringsAsFactors =
default.stringsAsFactors(), encoding = "unknown")
⤷ The header argument specifies if the first line is a header or not
⧙ If not: header=FALSE
⧙ If yes: header=TRUE
⧙ If you use headers, then all columns should have a header otherwise this will provide an error!
⤷ The “sep” argument specifies what the separator between the different columns is
⧙ Can be a symbol or nothing (write nothing between “”)
⧙ Is dependent on the file itself
⧙ If you’re data has white spaces these can cause issues with R not reading the lines correctly
and seeing them as separate columns, in this instance write: sep=“\t”
⤷ The dec argument specifies what symbol R will treat as a decimal separator
⧙ By default this is a dot (“.”)
⧙ In Belgium we use a “,” so change accordingly
⤷ Na.strings are used to define what ‘empty’ or undefined cells are and how R should be able to
find them
⧙ Na.strings = NA is the default
⧙ Make sure that these are used in cells with no value/data because other symbols won’t be
recognized by R unless they are specified here (you then replace NA with that symbol)
❣ You can then assign a term to this table and allow R to save it in the workspace
⤷ Command: myData <- read.table(file="X",sep="Y",header=Z)
⧙ X=file name
⧙ Y=separator symbol
⧙ Z= True or False dependent on your table
⤷ If you then write the given term (here: myData) you will get the saved data (here a table)

,❥ Make a table using data provided in R
❣ write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ", eol =
"\n", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE, qmethod =
c("escape", "double"))
❣ x = file in matrix or data frame
❣ file = “”: here you fill in your file name and filetype
❣ append: If TRUE, the output is appended to the file. If FALSE, any existing file of the name is
destroyed.
❣ Na = NA: missing values will be indicated with NA

Types of data
Numeric Integer or floating point Decimal or whole numbers
Character Text string Texts, always in “”
Categorical variable with limited number of levels Categories (represent groups)
Factor
Ordered or not The different possible categories are levels
Logical TRUE or FALSE
❥ You can convert data type as follow:
❣ as.X(Y)
❣ With: X = numeric, character, factor or logical and Y = your data

Data structures
1-dimensional matrix (or : column)
All elements of same data type (numeric, logical...)
Vector
Concatenate operator:
c(5 , 9.8 , 5.4 , 2.0)
2 dimensional table
Matrix All elements of same type (typically numeric)
More dimensions = array
typical’ 2-dimensional data set
Variables in columns, records in rows
Data frame Variables can be different types of data
Composed of vectors, with each column=vector
Extract column using $ operator : df$column
Any combination of other objects (components)
List
Results of analysis
❥ Using X$Y, with X being the dataset or given term to dataset, you can display Y
❥ Using class(X), with X being the dataset or given term to dataset, you can determine what class it
is
❥ Using class(X$Y), with X being the dataset and Y being the variable, you can see what class Y is
❥ If a variable is classed incorrectly you can correct it: X$Y <- as.A(X$Y) with A being the correct
class
❥ Using str(X), idem, you can have a more comprehensive overview of your dataset
❥ Using view(X), idem, you can view your dataset clearly in table format
❥ Using names(X) you can get the labels/names of your variables
❥ Using dim(X) you can get the dimensions (row x columns) of your data
❥ Alternatively, you can see rows and columns separately using nrow(X) and ncol(X)
❥ Using length(X$Y) you can see how many rows are present in that specific variable

, ❥ You can change a numeric variable into a categoric one
❣ So if a variable is represented in numbers in the dataset, but these number actually refer to a
certain label you can use this command to tell R that
❣ Command: X$Y <- factor(X$Y, levels = c(1,2,3) , labels = c("A","B","C")) with
A-C your chose labels
❣ Example:
⤷ The variable workshop is divided into a value from 1-3 but these actually represent the following
labels; 1=R, 2=SAS and 3=SPSS
⤷ Command: X$workshop <- factor(X$workshop, levels = c(1,2,3) , labels =
c("R","SAS","SPSS"))
❥ These commands will both provide a summary of a given variable in a dataset (both do the same):
❣ summary(X$Y) OR table(X$Y)

Making a new variable
❥ Using this command you can make a new variable out of an existing one: X<-ifelse(test, yes,
no)
❣ X = name of new variable
❣ Ifelse: returns a value with the same shape as test
❣ Test: the existing variable you’re using + a certain condition (e.g. BMI < 25)
❣ Yes: value assigned if the condition is TRUE
❣ No: value assigned if the condition is FALSE
❣ Example: myData$pass <- ifelse(myData$exam>=10,TRUE,FALSE)
⤷ Makes a new variable in the dataset “myData” called “pass” based on the variable “exam”
⤷ If a value is >=10 it gets a TRUE if not it gets a FALSE
❥ Using this command you can make a new variable in a class of your choosing out of an existing
variable: myData$pass2 <- as.numeric(myData$pass)

Exporting a modified table
❥ The following command writes a new table: write.table()
❣ You can also add more arguments to specify what you want
⤷ write.table(X, file = "Y", append = FALSE, quote = FALSE, sep = "\t",eol =
"\n", na = "NA", dec = ".", row.names = FALSE, col.names = TRUE, qmethod =
c("escape", "double"),fileEncoding = "")
⤷ X = object you want to export
⤷ Y = name you want to give the exported object

file Name of newly made file
If TRUE, the output is appended (added to end of) to the file. If FALSE, any existing file of
append
the name is destroyed.
If TRUE, any character or factor columns will be surrounded by double quotes. If a
quote numeric vector, its elements are taken as the indices of columns to quote. In both cases,
row and column names are quoted if they are written. If FALSE, nothing is quoted.
sep The field separator string. Values within each row of x are separated by this string.
na The string to use for missing values in the data.
The string to use for decimal points in numeric or complex columns: must be a single
dec
character.
row.names/ If TRUE row and/or column names are written. If no names are present, numbers are
col.names added instead.

Document information

Study
Uploaded on
August 6, 2026
Number of pages
29
Written in
2025/2026
Type
Summary
$13.25

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
2
Followers
0
Items
39
Last sold
3 days ago


Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions