100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Samenvatting

Summary Advanced data anaylsis

Beoordeling
-
Verkocht
-
Pagina's
102
Geüpload op
08-07-2024
Geschreven in
2023/2024

This document contains detailed step-by-step instructions for programming with RStudio based on the Advanced Data Analysis course ready to be used during the practical exam. It includes the answers to all questions that appear on practical documents posted during the course as well as class notes, graphics, images of the RStudio steps and extra information to understand the different symbols and instructions of the RStudio program.

Meer zien Lees minder











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Documentinformatie

Geüpload op
8 juli 2024
Aantal pagina's
102
Geschreven in
2023/2024
Type
Samenvatting

Voorbeeld van de inhoud

CRM Advanced data analysis: Exam preparation Mar’2024




EXERCICE 1
BEFORE YOU START

 Create a new script file  File  New File  R Script. The screen is split into 4 quadrants:

o The script editor (top left) : visualizing the script file with your R-commands.

o The command prompt (bottom left) : Here you can directly type in commands at the prompt. Easy
for a quick check or calculation that you don’t want to include into the code.

o The workspace (top right) : This stores all objects you have defined (see later).

o Output panel (bottom right) : Here you can see plots, look for help, select packages (see later)

TELLING WHERE IS THE DIRECTORY

 Using the setwd() command you can see where the current working directory is:


o Need to change the direction of the slashes  from "\" to "/"

o Do not forget the quotes (" ") inside the command

 To change the working directory, go to Session/Set working
directory/Choose directory and browse to the C:\temp. The
function setwd() does exactly the same thing (using forward slashes!):

 Check that the working directory has changed.

 Using the list.files(getwd())function, you can get an overview
of the files that are in your working directory. Set or get???  així
tens una vista dels documents, I pots veure el nom amb els que estan guradats  t’estalvies
haver-ho d’escriure !!! fer-ho com a segon pas abans de (read.table)

READING IN A TABLE

EXCEL FILE PREPARATI ON

Prepare the excel making sure that:

 Add a header (ID) in the first column (identification of the subjects)  header =TRUE
 Cells with an excel formula: better the calculated value by its real value.

1

,CRM Advanced data analysis: Exam preparation Mar’2024


 We need (.) instead of comas (,) need to be specified  already by default.
 Delete brackets
 Avoid white spaces (in this case on the names), delete it instead  sep
 Missing value indicator (?) need to be specified  na.strings = "?"


ID-variable has been interpreted as a factor with 12 levels. Hence, internally the ID will be considered as a
number. We’d rather have it as a character vector  myData$ID <- as.character(myData$ID)

to make sure it has changed:

 class(myData$ID)
str(myData)


º X

 To create a tab-delimited (.txt) file, go to File\ save as\ Save as type text (Tab


delimited)(.txt).

 You get a warning that the document may contain features not compatible with the .txt
format, and that you are only saving the active sheet. Click OK/yes. Quit the excel
workbook without further saving (you already did save your workbook before).

 check if the .txt document has been created.

 The R-function to read in the table is read.table().At the command prompt (bottom left


panel)

 File (mandatory, the name) within quotes.First argument is the name of the file: (data(1).txt in this
case).
 header: first column names: header=TRUE
 stringsAsFactors: indication that there are text strings that need to be read in as factors. 
StringAsFactors=TRUE

 sep: indication that there as white spaces. In case you get the warning “More columns than column
names”  sep=”\t”
 Indicates that there is a missing value, that need to be considered (by default is “na”  na.strings
= "?"

2

,CRM Advanced data analysis: Exam preparation Mar’2024


 We need (.) instead of comas (,) need to be specified  dec = "."

 Ask for help on the by typing ?read.table.

SAVING AN OBJECT

 Using the assignment operator (<-), you have given a name to the data you’ve read in. This object
is called “myData” appear in the top right panel of R Studio.




o myData <- read.table(file="data1.txt",sep="\t",header=T)

 If you want to see your saved object: Type the word “myData” at the prompt (bottom left panel in
RStudio). Remember, R is case sensitive!! “myData” is not the same as “MYDATA” or “mydata”!!

CALCULATIONS

Object: myX<- seq(from=-3,to=3,by=0.5)  vector

 From (start)
 To (final)
 By (increment)  how large the steps are.

 mean(myX)  calculate the mean
 sum(myX)  calculate the summation

A vector is the elementary structure for data handling in R. It is a set of
simple elements, all being objects of the same class. For example, a
simple vector of the numbers one to three can be constructed by one of
the following commands:



DATA STRUCTURE

 What kind of data structure would it be? Use the class function. class(myData)

 The variables in the data frame myData are of different data types:

o factor (=categorical variable with limited number of levels, ordered of not.

o num(eric) and int(eger)  both of which represent numeric variables.

3

, CRM Advanced data analysis: Exam preparation
Mar’2024

o character (=text string)

o logical (TRUE or FALSE).


 The gender of the persons in our dataset are stored as a factor  class
(myData$gender)

 The levels of the factor can be extracted using the levels function  levels(myData$gender)




 A more comprehensive overview of the current data structure  str(myData)

 The output tells you again that ‘myData’ is an object of class data frame, how many
observations and variables, and what type of data the different variables represent.

 In R, the names of the variables are an entire part of the data frame  names(myData)




 The dimensions of the table  dim(myData)

 Number of rows and columns can be found using:

 nrow(myData)

 ncol(myData)

DATA TYPES AND COERCION

Changes in data type to one another:

 as.numeric()
 as.character()
 as.logical()
 as.factor()

 The individual variables are also objects, and belong to a class
class(myData$exam)

4
€13,46
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
clararubio

Maak kennis met de verkoper

Seller avatar
clararubio Universiteit Antwerpen
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
0
Lid sinds
1 jaar
Aantal volgers
0
Documenten
1
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen