Category Archives: Data Science

Learn R – How to Create Multiple Density Plots using GGPlot

This article represents code samples which could be used to create multiple density curve or plots using ggplot2 package in R programming language. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Multiple Density Curves/Graphs with GGPlot The code samples given below works for “diamonds” dataset which is loaded as part of ggplot2 package. Following are two different types of plots shown below: Density plots with multiple fills Density plot with single fill Density Plots with Multiple Fills:Following code represents density plots with multiple fills. Pay attention to the “fill” parameter passed to “aes” method. # Create density plots for …

Continue reading

Posted in Data Science. Tagged with .

Learn R – 3 Commands to Generate Random Numbers

This article represents 3 different commands with code examples which could be used to generate random numbers in R programming language. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following are the key points described later in this article: Runif command Sample command Rnorm command Difference between runif and rnorm command Runif: Generate Random Numbers based on Uniform Distribution “Runif” command can be used for generating random numbers based on uniform distribution. One can generate one or more random numbers within a range of numbers. One should note that the random numbers generated using runif commands are all …

Continue reading

Posted in Data Science. Tagged with .

Learn R – Extract Data Frame with One Column

This article represents code sample that could be used to create/extract data frame with one column from existing data frame. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Extract Data Frame with One Column In the code sample below, diamonds dataset from ggplot2 package is used. To work with the example below, one needs to load the ggplot2 library using command such as require(“ggplot2”). In the command below, method as.data.frame is used. Make a note of drop=false parameter passed to as.data.frame method. dfn1 <- as.data.frame(diamonds[,c(1)], drop=false)

Posted in Data Science. Tagged with .

Learn R – How to Create Histogram using GGPlot

This article represents techniques (commands samples) which could be used to create histogram using ggplot2 package in R programming. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following is the summary of commands used to create histogram using ggplot: Using simplistic ggplot and geom_histogram method Using ggplot and geon_histogram command with attributes such as col, fill, alpha Using ggplot, geom_histogram and  scale_fill_gradient method Common Techniques to Create Histogram using ggplot2 In the code examples below, diamonds dataset from ggplot2 package is used. To work with examples below, load the ggplot2 library prior to executing the commands given below. …

Continue reading

Posted in Data Science. Tagged with .

Learn R – How to Create Data Frames using Existing Data Frame

This article represents commands that could be used to create data frames using existing data frame. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. Following is a list of command summary for creating data frames by extracting multiple columns from existing data frame based on following criteria, whose sample is provided later in this article: Column indices Column names Subset command Data.frame command 6 Techniques for Extracting Data Frame from Existing Data Frames Following commands have been based on diamonds data frame which is loaded as part of loading ggplot2 library.   Following is how the diamonds data …

Continue reading

Posted in Data Science. Tagged with .

Learn R – 5 Techniques to Create Empty Data Frames with Column Names

This article represents techniques on how one could create an empty data frame with column names. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos. 5 Techniques to Create Empty Data Frames In each of the examples below, the data frame is created with three columns, namely, ‘name’, ‘rating’, ‘relyear’. It represents moview names, ratings, and the release year. # Command data.frame is used df1 <- data.frame(name=””, rating=””, relyear=””, stringsAsFactors=FALSE) # Command data.frame is used df2 <- data.frame(name=character(), rating=character(), relyear=character(), stringsAsFactors=FALSE) # Usage of read.table command to create empty data frame df3 <- read.table(text = “”, colClasses = c(“character”, …

Continue reading

Posted in Data Science. Tagged with .

Data Science – How to Scale or Normalize Numeric Data using R

This article represents concepts around the need to normalize or scale the numeric data and code samples in R programming language which could be used to normalize or scale the data. Please feel free to comment/suggest if I missed mentioning one or more important points. Also, sorry for the typos. Following are the two different ways which could be used to normalize the data, and thus, described later in this article: Why Normalize or Scale the data? Min-Max Normalization Z-Score Standardization Why Normalize or Scale the data? There can be instances found in data frame where values for one feature could range between 1-100 and values for other feature could …

Continue reading

Posted in AI, Big Data, Data Science. Tagged with , .