Newly created variables don't show up in data table ?

I created two new variables using my original data, but I can't get them to show up in my data set. I tried using mutate and a few other functions but I am not having any luck. I am assuming the variables need to be in the data table because next, I need to generate bar charts and box plots using all the data in the file. When I run summary(on my original data) my new variables don't show up either I have to run summary(on my new variables) separately in order to generate summary data.

Please help.
Kind regards,
Kristina

Here is a screenshot if it helps

mutate(), like other tidyverse functions, doesn't perform in-place modifications, you have to manually assign the changes to a new object (or the same object if you want) using the assign operator <-, take a look at this example.

library(dplyr)

new_df <- iris %>% 
    mutate(new_col = Sepal.Length + Sepal.Width) %>% 
    head(5)
new_df
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species new_col
#> 1          5.1         3.5          1.4         0.2  setosa     8.6
#> 2          4.9         3.0          1.4         0.2  setosa     7.9
#> 3          4.7         3.2          1.3         0.2  setosa     7.9
#> 4          4.6         3.1          1.5         0.2  setosa     7.7
#> 5          5.0         3.6          1.4         0.2  setosa     8.6

Hello! Thank you for the recommendation and the example. It was helpful. It turns out I do not have the add-on package dplyr and therefore the mutate function will not be an option for me. I was unable to download it from the Rstudio library because I have the open source version (3.6) of Rstudio. By chance is there any other option I have to add newly created variables to my data table if I have this basic open source version?

U can install Tidyverse with the following command:

install.packages("tidyverse")

After installation start it with

library(tidyverse)

It works for rstudio and R (3.6) and dplyr is one of the packages that are included in it.

I belive you are confusing R with Rstudio they are two different pieces of software, even though, using the open source version of Rstudio doesn't prevent you from installing any R package. (almost all of them are open source).
You just have to install it using

install.packages('dplyr')
1 Like

Hello!! Thank you for the response! Sorry for the delayed response. I ended up using a cbind() to include the newly created variables to my data table. I did try installing library("tidyverse") and it looked like they were installing correctly in the beginning and then at the last minute something went wrong (again). I will talk with my professor regarding why on earth I keep receiving the message that the open software is the problem.

Thanks again, I appreciate your help!

Hello!! Thank you for your help! Sorry for the delayed response. I ended up using a cbind() to include the newly created variables to my data table. I did try installing the install.packages('dplyr') and it looked like they were installing correctly in the beginning and then at the last minute something went wrong (again). I will talk with my professor regarding why on earth I keep receiving the message that the open software is the problem.

Thanks again, I appreciate your help and I'm sure I'll have more questions soon.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.