R does not return any values in Console when using pipes function

I am trying to complete this pipe function and R is not returning any values in the Console, it just keeps repeating the code. Not sure what I am doing incorrectly? I have already installed the tidyverse package and library as well as the dplyr package and library.

This is the R-Script:

filtered_toothgrowth <- ToothGrowth %>%
   filter(dose == 0.5) %>%
   group_by(supp) %>% 
   arrange(len)

The Console is just repeating the code:

> filtered_toothgrowth <- ToothGrowth %>%
+   filter(dose == 0.5) %>%
+   group_by(supp) %>% 
+   arrange(len)
> 
> filtered_toothgrowth <- ToothGrowth %>%
+   filter(dose == 0.5) %>%
+   group_by(supp) %>% 
+   arrange(len)
> 
> filtered_toothgrowth <- ToothGrowth %>%
+   filter(dose == 0.5) %>%
+   group_by(supp) %>% 
+   arrange(len)
> 

Your script assigns the output from the pipe to a new data frame named filtered_toothgrowth. If you click on the Environment tab in the upper right pane, you will see it listed. If you also want the output to appear in the console, just put the code in parentheses:

library(tidyverse)

(filtered_toothgrowth <- ToothGrowth %>%
  filter(dose == 0.5) %>%
  group_by(supp) %>% 
  arrange(len))
#> # A tibble: 20 × 3
#> # Groups:   supp [2]
#>      len supp   dose
#>    <dbl> <fct> <dbl>
#>  1   4.2 VC      0.5
#>  2   5.2 VC      0.5
#>  3   5.8 VC      0.5
#>  4   6.4 VC      0.5
#>  5   7   VC      0.5
#>  6   7.3 VC      0.5
#>  7   8.2 OJ      0.5
#>  8   9.4 OJ      0.5
#>  9   9.7 OJ      0.5
#> 10   9.7 OJ      0.5
#> 11  10   VC      0.5
#> 12  10   OJ      0.5
#> 13  11.2 VC      0.5
#> 14  11.2 VC      0.5
#> 15  11.5 VC      0.5
#> 16  14.5 OJ      0.5
#> 17  15.2 OJ      0.5
#> 18  16.5 OJ      0.5
#> 19  17.6 OJ      0.5
#> 20  21.5 OJ      0.5

Created on 2023-05-06 with reprex v2.0.2

You can also put the name of the new data frame on a separate line of code:

library(tidyverse)

filtered_toothgrowth <- ToothGrowth %>%
  filter(dose == 0.5) %>%
  group_by(supp) %>% 
  arrange(len)

filtered_toothgrowth
#> # A tibble: 20 × 3
#> # Groups:   supp [2]
#>      len supp   dose
#>    <dbl> <fct> <dbl>
#>  1   4.2 VC      0.5
#>  2   5.2 VC      0.5
#>  3   5.8 VC      0.5
#>  4   6.4 VC      0.5
#>  5   7   VC      0.5
#>  6   7.3 VC      0.5
#>  7   8.2 OJ      0.5
#>  8   9.4 OJ      0.5
#>  9   9.7 OJ      0.5
#> 10   9.7 OJ      0.5
#> 11  10   VC      0.5
#> 12  10   OJ      0.5
#> 13  11.2 VC      0.5
#> 14  11.2 VC      0.5
#> 15  11.5 VC      0.5
#> 16  14.5 OJ      0.5
#> 17  15.2 OJ      0.5
#> 18  16.5 OJ      0.5
#> 19  17.6 OJ      0.5
#> 20  21.5 OJ      0.5

Created on 2023-05-06 with reprex v2.0.2

Thank you! It was driving me mad and could not figure out what was going on. Just starting learning R and trying to figure out all the ropes, this is very good to know. So much appreciated! :grinning:

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.