How to read and import Excel files in R with tidyverse?

Use the readxl package to import contents of an Excel file from your file into a DataFrame Make sure to install the readxl library (or the tidyverse library) into RStudio or other R development environment before calling it from your script. Import Excel files into RStudio – Practical Example Step 1: Import the readxl library … Read more

How to write an R vector to a CSV or text file?

Proceed as shown in the example below to export an R vector object into a csv or text file. You can use this code on RStudio, Jupyter Notebook or other R dev environment. Step 1: Create an R vector We will define a vector composed from character strings. You could as well define a numeric … Read more

How to write excel multiple sheets in R?

Use the following code to export multiple DataFrame objects to an Excel workbook containing multiple sheets. Step 1: Create a list of DataFrames We will first define a simple list comprising two DataFrames that we would like to write into our Excel file. Step 2: Import the openxlsx package Next we will ensure that the … Read more

How to export an R list to Excel or csv files?

Follow these steps to export an R list object to a Microsoft Excel or csv files on Windows, macOS, Ubuntu or other Linux distribution: Step 1: Define an R list object We will start by defining a simple R list object composed of two vectors using the following code: Step 2: Convert your list to … Read more

How to keep specific columns by name in R DataFrames?

Subset R DataFrames by one or multiple column names To subset an R DataFrame and keep some of its columns use the following code: R-base: dplyr package: Initialize DataFrame To launch this tutorial, we will create a sample R DataFrame. Keep one or multiple columns with R base Use the subset function (part of R-Base) … Read more

How to print R Dataframe column names values?

You can list your R DataFrame column names by using the following methods: R base: Using dplyr: Using tidyverse: Using janitor: Get R column names – Practical Example Define sample DataFrame Run the following snippet in your R studio environment to create a DataFrame that we’ll use for this tutorial: List column names with R … Read more

How to convert an R DataFrame column to a list?

Use the following R Snippet to export a DataFrame column to a list in R: Or using dplyr: Write R column to a list – practical example Create R DataFrame We will first create a simple R DataFrame: Export R column to list with Dplyr Pull When using the dplyr library, we have several ways … Read more

How to get a year value from a date column in r?

To extract the year values from a date column in an R DataFrame, use the following code: Create sample data We will first create some a sample DataFrame that we will use in our practical example: Extract year value from datetime in R Using R base, we can create a new year column using the … Read more

How to merge multiple DataFrame columns into one in R?

To merge two or more R DataFrame columns into one, use one of the following options: Sample DataFrame Before getting started, go ahead and import the tidyverse package, which delivers libraries we’ll be using such as tydr and stringr- but also other key libraries such as dplyr and ggplot2. We then create a simple DataFrame … Read more