3.1 A Data Frame as a Dataset

20210103 A data frame is essentially a rectangular table (or matrix) of data consisting of rows (observations) and columns (variables). We can base::print.data.frame() to view a table, here choosing the first 10 observations of the first 6 variables of the ds dataset.

# Display the table structure of the ingested dataset.

ds[1:10,1:6] %>% print.data.frame()
##          date location min_temp max_temp rainfall evaporation
## 1  2008-12-01   Albury     13.4     22.9      0.6          NA
## 2  2008-12-02   Albury      7.4     25.1      0.0          NA
## 3  2008-12-03   Albury     12.9     25.7      0.0          NA
## 4  2008-12-04   Albury      9.2     28.0      0.0          NA
## 5  2008-12-05   Albury     17.5     32.3      1.0          NA
## 6  2008-12-06   Albury     14.6     29.7      0.2          NA
## 7  2008-12-07   Albury     14.3     25.0      0.0          NA
## 8  2008-12-08   Albury      7.7     26.7      0.0          NA
## 9  2008-12-09   Albury      9.7     31.9      0.0          NA
## 10 2008-12-10   Albury     13.1     30.1      1.4          NA

Alternatively we might sample 10 random observations (dplyr::sample_n()) of 5 random variables (dplyr::select()):

# Display a random selection of observations and variables.

ds %>%
  sample_n(10) %>%
  select(sample(1:ncol(ds), 5)) %>%
  print.data.frame()
##    wind_gust_dir min_temp       date wind_dir_9am wind_dir_3pm
## 1             NW     13.2 2024-09-23            W            E
## 2            ESE     10.5 2022-04-05            N            E
## 3           <NA>     -4.1 2017-07-09         <NA>         <NA>
## 4            WSW      7.0 2011-09-10            W          WSW
## 5            WNW     12.1 2014-06-01         <NA>            E
## 6              W     14.4 2025-04-03          WNW            W
## 7             SW     10.9 2024-12-13          WSW          WSW
## 8              W     10.3 2009-05-14          NNW          WSW
## 9             NE     13.5 2025-09-04          SSW           NE
## 10           SSE     14.7 2009-02-02          SSE          SSE

This tabular form (i.e., it has rows and columns) is common for data science and we refer to it as our dataset.



If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0