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

How to find cuberoot of a number in R?

How to find cuberoot of a number in R?

This recipe helps you find cuberoot of a number in R

0

Recipe Objective

This recipe demonstrates how to calculate a cuberoot of a numeric variable

There is no built-in function to specifically calculate the cuberoot of a number. But there are two different ways in which you can do this.

  1. Using the expontial arithmetic operator while defining a function;
  2. Using nthroot() function in pracma package with n =3

Step 1: Creating a numeric variable

We assign a number to a variable 'a' whose cuberoot needs to be calculated

a = -64

Step 2: Calculating Cuberoot in R

1) Defining a function using an exponential arithmetic operator:

We use the arithmetic operator " ^ " and defining a function 'cuberoot' to carry out this task. This defined function will deal with both positive and negative numeric variables.

# defining a function cuberoot in R that can accept an argument 'x' cuberoot = function(x){ if(x < 0) { - (-x)^(1/3)} else {x^(1/3)} } ​ # calling the function and giving a as an arguement cuberoot(a)
-4

2) Using nthroot() function with n = 3

we use the built-in function nthroot() with n=3 to calculate the cuberoot of a numeric variable. nthroot() is a function present in "pracma" package.

Syntax: nthroot(x,n)

Where:

  1. 'x' is a numeric vector
  2. n' is a positive integer specifying the exponent (1/n)
# installing the pracma package first install.packages("pracma") ​ #calling and exceuting nthroot function on 'a' pracma::nthroot(a, 3)
-4

Relevant Projects

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.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

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.

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.

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.

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

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.