How to read and import Text andExcel 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 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 check if an R DataFrame column contains a string value?

Use the stringr library str_detect function to check if a specific value is included in an R DataFrame column: Note: Make sure to install the stringr library (also included in tidyverse) before utilizing the str_detect function in your RStudio script or Jupyter notebook. Check if column contains value in R – Practical example Create a … Read more

How to create and write text files in R?

Sometimes during our data analysis process, we might need to quickly generate or modify data stored as txt files. In this tutorial we will learn how to programmatically create text files in your file system and append text to them using the R language. Create a text file We can use the file.create() method to … Read more

How to fix the there is no package called ‘tidyverse’ error in R?

Today we will learn how to fix error messages that you could find in your R development tool such as RStudio, Jupyter and others, when trying to invoke the tidyverse library without it being installed. Understanding the error Error in library(tidyverse) : there is no package called ‘tidyverse’ Here’s a screenshot from the RStudio Console … Read more

How to drop the last column of your R DataFrame?

In this short tutorial we’ll examine how you can use Base R and the dplyr library to remove the last (or multiple n last columns) of your DataFrame. Let’s start by building a simple R DataFrame from multiple vectors: This will return: [1] “city” “direct” “online” “partners” Remove DataFrame last column with Base R We … Read more