Data Wrangling Cheatsheet

Fellow Data Wranglers, while running the following code:
dplyr::select(iris,num_range("x",1:5)) # Select columns named x1, x2, x3, x4, x5

My output was:

dplyr::select(iris,num_range("x",1:5)) # Select columns named x1, x2, x3, x4, x5
data frame with 0 columns and 150 rows

This does not seem to agree with the expected output from the R Studio Data Wrangling Cheat Sheet.

Is this the correct output? If not, what should the expected output in the cheat sheet need to be changed to?

Unfortunately, as a new user I can't upload the actual cheatsheet but hopefully anyone that's reading through this post can see the screenshot I've tried to include.

Data Wrangling - Dplyr Helper Functions select num_range

Unfortunate example, because iris doesn't have any columns that begin with x, which explains the zero columns.

renames <- c("x1","y1","x2","y2","x3")
colnames(iris) <- renames
head(dplyr::select(iris,num_range("x",1:5)))
#>    x1  x2     x3
#> 1 5.1 1.4 setosa
#> 2 4.9 1.4 setosa
#> 3 4.7 1.3 setosa
#> 4 4.6 1.5 setosa
#> 5 5.0 1.4 setosa
#> 6 5.4 1.7 setosa
1 Like

Perfect! Thank you, I now understand what the code is meant to do.

1 Like

This topic was automatically closed 7 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.