Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Document preview thumbnail
Aperçu 3 sur 29 pages
Resume

Data Mining - Samenvatting Practicum

Document preview thumbnail
Aperçu 3 sur 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.

Aperçu du contenu

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.

Table des matières

  1. 01 Practicum 1: The Basics 1
    1. The working directory 1
    2. Working with tables in excel and text format 1
    3. Types of data 2
    4. Data structures 2
    5. Making a new variable 3
    6. Exporting a modified table 3
    7. Indexing 4
    8. Sorting 5
    9. Conditional selection 6
    10. Splitting, stacking and merging files 6
    11. Plotting 7
  2. 02 Practicum 2: Statistical Analysis 9
    1. T-test 9
    2. Parametric testing 10
    3. Linear regression 11
    4. Analysis of variance 12
  3. 03 Practicum 4: PCA 15
    1. Data reading and organisation 15
    2. The principal compontent analysis 15
    3. Cluster analysis 21
    4. Hierarchical clustering 21
    5. Partitional clustering 22
  4. 04 Practicum 5: Multiple linear regression 23
    1. Introduction 23
    2. ANCOVA 23
    3. Linear mixed models 26

Infos sur le Document

Publié le
6 août 2026
Nombre de pages
29
Écrit en
2025/2026
Type
Resume
€11,16

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Vendu
5
Abonnés
0
Éléments
39
Dernière vente
3 semaines de cela



Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions