How to find proportions of a vector in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to find proportions of a vector in R?

How to find proportions of a vector in R?

This recipe helps you find proportions of a vector in R

0

Recipe Objective

While carrying out a statistical analysis on a set of observations collected, finding proportions of these observations that meets a particular condition is most common. ​

To carry out this task, we will follow the following steps: ​

  1. Applying a condition on the vector which is also knwon as boolean test to get a vector of boolean values.
  2. Now passing these boolean values to the mean() function to get the proportion of all the TRUE values

In this recipe, we will discuss how to find proprtions of a vector in R discussing the above steps in details. ​

Step 1: Creating a numeric Vector

We will use a sales example in this case by creating a vector of no of sales of a certain product that took place in a period of 12 months. sales_data = c(5500, 2400, 2500, 2100, 2300, 2600, 2700, 2800, 2300, 3500, 6000, 7500)

Step 2: Apply a boolean test

Finding the sales which are greater than 5000. bool_test_results = sales_data > 5000 bool_test_results

TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE

Step 3: Finding the proportion of the vector

Find the proportion of the sales that are greater than 5000 ​

mean(bool_test_results)
0.25

This means that 25% of the sales were higher than 5000 in a period of 12 months. ​

Relevant Projects

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.