In this post, we will see how to subset a dataframe or select rows based on their position. We will first use dplyr's slice() function to slice a dataframe by location and then show how to select rows by position using base R Let us load tidyverse suite of R packages … [Read more...] about How to Select Rows of a dataframe by position
dplyr
How to replace NA in a column with specific value
In this tutorial we will learn how to replace missing values/NA in a column with a specific value. We will replace NA in a column using two approaches. At first we will use dplyr function mutate and ifelse to identify the element(s) with NA and replace with a specific value. Next … [Read more...] about How to replace NA in a column with specific value
How to add row number within each group in dplyr
In this tutorial, we will learn how to add row numbers with in each group of a dataframe in R. We will use combination of group_by() and row_number() functions from dplyr to add row number by group. To get started let us load tidyverse and palmer penguin datasets. Here we … [Read more...] about How to add row number within each group in dplyr
How to select one or more columns from a dataframe
In this tutorial we will learn how to select one or more columns/variables from a data frame in R. We first learn how to select the columns of interest with dplyr's select() function by using their name and then we will learn how to select columns using base R approach. Let … [Read more...] about How to select one or more columns from a dataframe
How to rename one or more columns of a dataframe
In this tutorial, we will learn how to rename one or more columns of a dataframe in R. We will use rename() function in dplyr R package to change the name of a single column first and then see an example of using rename() function to rename more than one columns. Let us get … [Read more...] about How to rename one or more columns of a dataframe