How to create arrays with specified dimension in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to create arrays with specified dimension in R?

How to create arrays with specified dimension in R?

This recipe helps you create arrays with specified dimension in R

0

Recipe Objective

Array is a type of object or data structure in R-language. They are designed to store values of same data-type in multiple dimensions. For example, if you wish to create an array of dimensions (3,5,4), then it will return 4 arrays each having 3 rows and 5 columns.

This recipe demonstrates how to create an array based on a specific dimension using 2 vectors.

Step 1: Creating 2 vectors

We create 2 different sized vectors using c() function

a = c(2,4,6,8,10,12,14) b = c(3,6,9,12,15,18,21,24,27)

Step 2: Creating an array

We use array() function to create an array in R-language.

Syntax: array(data, dim, dim_names)

where:

  1. data = vectors
  2. dim = dimension of the array (rows,columns, array_count)
  3. dim_names = names of the rows/columns specified. (optional arguement)

We now use this function to create an array with 2 rows, 3 columns and 1 array count from 2 vectors. i.e. dimension = (2,3,1)

array_ = array(c(a,b), dim = c(2,3,1)) print(array_)
, , 1

     [,1] [,2] [,3]
[1,]    2    6   10
[2,]    4    8   12

Relevant Projects

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.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

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.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

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

Census Income Data Set Project - Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based on census data.

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

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.

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.