Load packages
library(tidyverse)
Load data
We can use any one of the following script to import data
irisdata <- read.csv('https://raw.githubusercontent.com/rbiology/rbiology.github.io/master/_data/irisdata.csv')
irisdata <- read.csv("irisdata.csv")
irisdata <- read_csv("irisdata.csv")
## Parsed with column specification:
## cols(
## Sepal.Length = col_double(),
## Sepal.Width = col_double(),
## Petal.Length = col_double(),
## Petal.Width = col_double(),
## Species = col_character()
## )
Size:
Find dimensions of data. Returns a vector with the number of rows in the first element, and the number of columns as the second element (the dimensions of the object):
dim(irisdata)
## [1] 150 5
Number of rows of data:
nrow(irisdata)
## [1] 150
Number of columns of data:
ncol(irisdata)
## [1] 5
Content:
Show the first 6 rows:
head(irisdata)
## # A tibble: 6 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.10 3.50 1.40 0.200 setosa
## 2 4.90 3.00 1.40 0.200 setosa
## 3 4.70 3.20 1.30 0.200 setosa
## 4 4.60 3.10 1.50 0.200 setosa
## 5 5.00 3.60 1.40 0.200 setosa
## 6 5.40 3.90 1.70 0.400 setosa
Show the last 6 rows:
tail(irisdata)
## # A tibble: 6 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 6.70 3.30 5.70 2.50 virginica
## 2 6.70 3.00 5.20 2.30 virginica
## 3 6.30 2.50 5.00 1.90 virginica
## 4 6.50 3.00 5.20 2.00 virginica
## 5 6.20 3.40 5.40 2.30 virginica
## 6 5.90 3.00 5.10 1.80 virginica
Names:
Return the column names
names(irisdata)
## [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
## [5] "Species"
It is synonymous to colnames(irisdata)
Return row names
rownames(irisdata)
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11"
## [12] "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22"
## [23] "23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33"
## [34] "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44"
## [45] "45" "46" "47" "48" "49" "50" "51" "52" "53" "54" "55"
## [56] "56" "57" "58" "59" "60" "61" "62" "63" "64" "65" "66"
## [67] "67" "68" "69" "70" "71" "72" "73" "74" "75" "76" "77"
## [78] "78" "79" "80" "81" "82" "83" "84" "85" "86" "87" "88"
## [89] "89" "90" "91" "92" "93" "94" "95" "96" "97" "98" "99"
## [100] "100" "101" "102" "103" "104" "105" "106" "107" "108" "109" "110"
## [111] "111" "112" "113" "114" "115" "116" "117" "118" "119" "120" "121"
## [122] "122" "123" "124" "125" "126" "127" "128" "129" "130" "131" "132"
## [133] "133" "134" "135" "136" "137" "138" "139" "140" "141" "142" "143"
## [144] "144" "145" "146" "147" "148" "149" "150"
Summary:
Show the structure of the object and information about the class, length, and content of each column
str(irisdata)
## Classes 'tbl_df', 'tbl' and 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : chr "setosa" "setosa" "setosa" "setosa" ...
## - attr(*, "spec")=List of 2
## ..$ cols :List of 5
## .. ..$ Sepal.Length: list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Sepal.Width : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Petal.Length: list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Petal.Width : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Species : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## ..$ default: list()
## .. ..- attr(*, "class")= chr "collector_guess" "collector"
## ..- attr(*, "class")= chr "col_spec"
Summary statistics for each column
summary(irisdata)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## Length:150
## Class :character
## Mode :character
##
##
##
<– Click here to go to the previous tutorial Click here to go to the next tutorial –>