datasetR – R package for creating datasets

The datasetR helps you generate a random datasets for your R project. It provides a preset random list of values with different data types (interval, ordinal, nominal values). It includes also a function for imputing a NULL, NA or missing values.

Installing the package

datasetR package can be installed and downloaded from this Github repository using devtools package. More on devtools package.

Installing is done using:

library(devtools)
install_github("tomaztk/datasetR")

Getting started

The main function in the packes is  dsR() and it will help you generate the dataset. But first, let’s create a list with 20 different variable types and a random values.

library(datasetR)
set_of_val <- set_of_val

And you will get a starting set of values:

Data Types

in the sample list (set_of_val) there are many different data types, helping you create a dataset.

Understand the predefined list of values for constructing the datasets.

Types explained:

  1. ms: multi-class type of nominal data; all values are equal and no ordering can be done. Available:
    • color
    • continents
    • imaginary ZIP codes
    • capital cities
  2. od: ordinal data; values can be assigned order and comparison can be created. Available:
    • clothing size
    • classes from 1 to 6
  3. li: likert scale data; questionnaire type of data and values can be sorted. Available:
    • three-value scale for expressing opinion
    • five-value scale for expressing opinion
    • seven-value scale for expressing opinion
  4. bo: boolean data; with values of TRUE and FALSE
  5. bi: binary data with two outcomes. Available:
    • character type of values Yes and No
    • integer type of values 0 and 1
  6. le: single character values of alphabet letters. Available:
    • lowercase letters
    • uppercase letters
  7. gu: alpha-numeric character string of 16 bytes length, v4; known as Globally unique identifier (GUID or UUID)
  8. te: numeric data of temperature with no specific unit of measure. Available:
    • temperature (pref. °C) with range from -20 to 35
    • temperature (pref. °C) with range from 1 to 130 (integer type)
  9. mo: numeric data of money with no specific unit.

erer

Generating your random dataset

With the following example, the code will create a dataframe of 100 rows with total of 8 variables. The 8 variables will be type:

  1. 3 x multi-class (nominal with multiple classes; characters or numbers)
  2. 4 x two-class (nominal with two (binary) class ; characters or numbers)
  3. 1 x interval (integer)

The dimensions of the dataset is 8 variables and 100 rows of sampled data.

library(datasetR)
library(dplyr)

my_dataset <- dsR(vr="ms:3;bi:4;ii:1", nr=100);

Generating your desired

When you want to create a desired dataset, use the vr parameter and construct the string for the values. The string is annotated as type : number of variables . When stating multiple types, make sure to separated them with semi-colon.

test_data <- dsR(vr="od:1;ms:1;bi:1;ii:1", nr=10);

And following statements will generate the dataset of the same dimension.

test_data <- dsR(vr="od:1;od:1", nr=10);
test_data <- dsR(vr="od:2", nr=10);

Adding missing values to your dataset

When you want to skew your dataset, you can add some missing values to your desired data. By using addMissingValues on a desired dataset and desired column, the values will get replaced by NA values. In addition, the parameter pc is for percent of values for given dataframe.column that you want to replace.

mydataset$ii_1 <- addMissingValues(my_dataset, ii_1, pc = 10)

Feel free to post ideas, comments, bugs, improvements.

Tagged with: , , , ,
Posted in R
3 comments on “datasetR – R package for creating datasets
  1. […] article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

    Like

  2. […] Tomaz Kastrun has been busy: […]

    Like

  3. datasetR seems like a game-changer for data enthusiasts! This R package promises an efficient way to create datasets. Can’t wait to explore its capabilities. 📊📈 #DataScience #RProgramming

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

tenbulls.co.uk

tenbulls.co.uk - attaining enlightenment with the Microsoft Data and Cloud Platforms with a sprinkling of Open Source and supporting technologies!

SQL DBA with A Beard

He's a SQL DBA and he has a beard

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

R news and tutorials contributed by hundreds of R bloggers

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...