What is rowmeans and colmeans in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# What is rowmeans and colmeans in R?

This recipe explains what is rowmeans and colmeans in R

0

## Recipe Objective

Exploratory Data Analysis is a crucial step before building any machine learning model on a dataset. This also includes gathering statistical inferences from the data. There are a few main terms in statistics which describes the central tendency of the variables i.e. means and medians. R gives us the flexibilty to calculate these measures row-wise and column-wise.

This recipe focuses on using rowMeans() and colMeans() functions.

rowMeans() function calculates the means of of all the rows in the dataset and displays the output

colMeans() function calculates the means of all the columns in the dataset and displays the output

# Data manipulation package library(tidyverse) ​ # reading a dataset customer_seg = read.csv('R_77_Mall_Customers.csv') ​ glimpse(customer_seg)
Rows: 200
Columns: 5
\$ CustomerID              1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1...
\$ Gender                  Male, Male, Female, Female, Female, Female, ...
\$ Age                     19, 21, 20, 23, 31, 22, 35, 23, 64, 30, 67, ...
\$ Annual.Income..k..      15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 19, ...
\$ Spending.Score..1.100.  39, 81, 6, 77, 40, 76, 6, 94, 3, 72, 14, 99,...

Dataset description: It is the basic data about the customers going to the supermarket mall. We are interested in all the numeric variables in the dataset.

## Step 2: Using rowMeans()

# calculating means of every row apart ignoring the values in the 2nd column as it is categorical rowMeans(customer_seg[,-2])

## Step 3: Using colMeans()

# calculating means of every column apart ignoring the values in the 2nd column as it is categorical in nature colMeans(customer_seg[,-2])
CustomerID100.5Age38.85Annual.Income..k..60.56Spending.Score..1.100.50.2

#### Relevant Projects

##### Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

##### Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

##### Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

##### Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

##### 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.

##### Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

##### 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.

##### German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

##### Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.