R - Generate Random Names - Random Number - Random Date

R - Generate Random Names - Random Number - Random Date

This tutorial is focused to generate random values and create dummy dataset.

If you are very good in understanding the business and business attribute then this tutorial will help you creating a dummy data-set.

Basically there are three types of attributes:

  1. Numeric/Integer
  2. Character/Factor
  3. Dates

Below is the code which help you to generate any type of dummy data:

list.of.packages <- c("randomNames")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
repo='http://nbcgib.uesc.br/mirrors/cran/'
if(length(new.packages)) install.packages(new.packages, repo = repo)
lapply(list.of.packages, require, character.only = TRUE)

# Set Seed to replicate the same result
set.seed(1)
random_customer_id <- random_dealer_ID <- sample(19000:19999,100,replace=FALSE)
random_customer_name <- randomNames(100 ,which.names="both",name.order="first.last",name.sep=" ",sample.with.replacement=FALSE)

random_bill_type <- sample(c("Mobile","Electricity","Water"),100,replace=TRUE)

random_customer_bill_last <- sample(seq(as.Date('2016/06/01'), as.Date('2016/12/01'), by="month"), 100 ,replace=TRUE)
random_customer_bill_paid <- sample(100:3000,100 ,replace=TRUE)

dummy_df <- data.frame(customer_id = random_customer_id, customer_name = random_customer_name, bill_type=random_bill_type, bill_last_date = random_customer_bill_last, bill_amount = random_customer_bill_paid)

head(dummy_df)
> head(dummy_df,10)
## Do not copy
 customer_id customer_name bill_type bill_last_date bill_amount
1 19265 Samantha Duncan Electricity 2016-11-01 2797
2 19371 Jonathan Ransom Water 2016-12-01 2713
3 19571 Jopour Xiong Electricity 2016-07-01 2278
4 19905 Dixa Horton Electricity 2016-11-01 2062
5 19200 Meghan Allen Electricity 2016-12-01 1979
6 19893 Shedrick Cheung Water 2016-12-01 312
7 19939 Deray Billings Electricity 2016-08-01 1328
8 19656 Ross Fairbanks Water 2016-08-01 1639
9 19624 Jahlysa Jones Water 2016-12-01 2834
10 19061 Lisbel Sandoval Ramirez Electricity 2016-06-01 2166

Output: Here you will get a well sampled dummy data. Utilize this for as per your business rules.

1

Leave a Comment