In this brief tutorial, you will learn how to add a column to a dataframe in R. More specifically, you will learn 1) to add a column using base R (i.e., by using the $-operator and brackets, 2) to add a column using the add_column() function (i.e., from tibble), 3) to add multiple columns, and 4) to add columns from one dataframe to another.

In Psychological research, there are instances when we need to merge data from different sources. For example, suppose we have collected data on participants’ personality traits using a self-report questionnaire and their performance on a cognitive task. The personality data may be stored in one dataframe, while the cognitive task data is in another dataframe. To analyze the relationship between personality and cognitive performance, we need to combine these datasets. In such cases, we may need to add a column from one DataFrame to another in R. By adding a column from one dataframe, containing the personality data, to the dataframe with cognitive task data, we can create a unified dataset. This allows us to investigate how individual personality differences relate to cognitive performance. Adding a column to a dataframe in R provides us with the flexibility to merge and integrate various data sources, enabling comprehensive analyses that consider multiple factors. This approach enhances the depth and richness of our understanding of psychological phenomena and facilitates more nuanced interpretations of research findings.
Note, when adding a column with tibble we are, as well, going to use the %>% operator which is part of dplyr. Note, dplyr, as well as tibble, has plenty of useful functions that, apart from enabling us to add columns, make it easy to remove a column by name from the R dataframe (e.g., using the select() function).