How to Download and Install R on Windows

In this short tutorial, you’ll see how to download and install R on Windows. You’ll also see how to run a simple script in R. Steps to Download and Install R on Windows Step 1: Download R To start, go to cran.r-project.org/bin/windows/base, and then click on the link to “Download R for Windows.” Step 2: … Read more

Check the Data Type of each DataFrame Column in R

Here are 2 ways to check the data type of each DataFrame column in R: (1) Using str(): Copy str(df) (2) Using sapply() and class(): Copy sapply(df, class) Next, you’ll see a simple example with the steps to: Steps to Check the Data Type of each DataFrame Column in R Step 1: Create a DataFrame … Read more

How to Export a DataFrame to Excel in R

The writexl package can be used to export a DataFrame to Excel in R: Copy library(“writexl”) write_xlsx(The DataFrame name, “Path to store the Excel file\\file name.xlsx”) Steps to Export a DataFrame to Excel in R Step 1: Install the writexl package Type the following command in the R console to install the writexl package: Copy … Read more

How to Add R to Jupyter Notebook (full steps)

You can add R to Jupyter Notebook by typing the following command in the Anaconda Prompt: Copy conda install -c r r-irkernel Here are the full steps to add R to Jupyter Notebook. Steps to Add R to Jupyter Notebook Step 1: Open the Anaconda Prompt To start, open the Anaconda Prompt. You’ll then see … Read more

How to Import an Excel File into R (example included)

To import an Excel file into R using the readxl package: Copy library(“readxl”) df = read_excel(“Path where your Excel file is stored\\File Name.xlsx”) print(df) To import a specific sheet within the Excel file: Copy library(“readxl”) df = read_excel(“Path where your Excel file is stored\\File Name.xlsx”, sheet=”Your sheet name”) print(df) Note: for previous versions of Excel, … Read more

How to Install a Package in R (example included)

The following template can be used to install a package in R: Copy install.packages(“package_name”) For demonstration purposes, you’ll see how install the readxl package. This package is used to import Excel files into R. The same steps reviewed here can be used to install other packages in R. Steps to Install a Package in R … Read more

Example of Multiple Linear Regression in R

In this short guide, you’ll see an example of multiple linear regression in R. Here are the topics to be reviewed: The Steps Step 1: Collect and capture the data in R Imagine that you have a fictitious economy, and your goal is to predict the index_price (the dependent variable) based on two independent/input variables: … Read more

How to Create a DataFrame in R (with Examples)

Generally speaking, you may use the following template in order to create a DataFrame in R: Copy first_column <- c(“value_1”, “value_2”, “value_3”) second_column <- c(“value_A”, “value_B”, “value_C”) df <- data.frame(first_column, second_column) print(df) Alternatively, you may apply this structure to get the same DataFrame: Copy df <- data.frame(first_column = c(“value_1”, “value_2”, “value_3”), second_column = c(“value_A”, “value_B”, … Read more

How to Export DataFrame to CSV in R

Here is a template that you may use to export a DataFrame to CSV in R: Copy write.csv(DataFrame Name, “Path to export the DataFrame\\File Name.csv”, row.names=FALSE) And if you want to include the row.names, simply change it to TRUE. In the next section, you’ll see an example with the steps to export your DataFrame. Steps … Read more

How to Import a CSV File into R (example included)

To import a CSV file into R: Copy df = read.csv(“Path where the CSV file is stored\\File Name.csv”) print(df) Example of importing a CSV file into R Let’s say that you have the following data stored in a CSV file (where the file name is ‘Products‘): item_name price Desk 400 Tablet 150 Printer 85 Laptop 1300 … Read more