7 💻 data cleaning in R

Data wrangling also said data cleaning are the preparation steps prior fitting any statistical procedure. This is needed since data, the most of the times, comes in a raw diry format. Why data come in a raw/dirty format? people organise and treat data badly

7.1 Intro to R

Let’s start from the basics!

3+5
#> [1] 8
12/7
#> [1] 1.714286

store result into objects

result <- 3 + 5
result
#> [1] 8

then print them:

print(result)
#> [1] 8

add operation to R objects

result <- result * 3.1415
print(result)
#> [1] 25.132

let’s define a vector (which is an object type)

vector = c(1, 3, 8, 13)
vector
#> [1]  1  3  8 13

How can we acccess to vectors? we need square brackets object[]. Dont be confused with dataframes, in that object class (i.e. dataframe are object classes, so R objects with certain characteristics ).

get first element (paly with it )

vector[1]
#> [1] 1

now to first 3 elements, notice the : that means: “fino a” i.e. da 1 fino a 3, positional arguments

vector[1:3]
#> [1] 1 3 8

sto finendo di scrivere