%>% What are these symbols/characters used for in R?

0 votes

I recently saw a code as shown below:

text_df %>%
  unnest_tokens(word,text_df, to_lower=FALSE)

I am unable to understand the usage of %>% symbol.

Aug 27, 2018 in Data Analytics by Anmol
• 1,620 points
26 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
The %>% is the pipe operator used to divide the code multiline pipping, this is done just to increase the usability.

It has same functioning as of <- symbol with a addition to take multiline commands
answered Aug 27, 2018 by ANMOL
• 3,620 points
0 votes

It is a forward-pipe operator.

You can use it to pass the left-hand side input through the right-hand side operator. In mathematical terms, it is the following operation:

x%>%f which translates to f(x)

Here is a simple example, where I create a vector of values, take the root square of every number and then compute the sum:

c(1,2,3,4) %>% Map(sqrt, .) %>%  Reduce(sum, .)
# The output: [1] 6.146264
It is very useful when you need to apply many different transformations to your data and don’t want to save the intermediate results or have many opening and closing function parentheses.

Consider writing the following:

x %>% impute %>% shuffle %>% pivot
versus the alternative:

pivot(shuffle(impute(x)))
I hope you get the point by now.

Moreover, this technique is very handy when cleaning data.

You can use it in your R session by loading the magrittr package: library(magrittr)

answered Aug 29, 2018 by zombie
• 3,690 points

Related Questions In Data Analytics

0 votes
1 answer

What are the options for deploying models in production with R?

Well, I could say that the answer ...READ MORE

answered Apr 12, 2018 in Data Analytics by DataKing99
• 8,100 points
148 views
0 votes
1 answer

List packages are used for data mining in R?

You can refer to the following packages ...READ MORE

answered Jul 3, 2018 in Data Analytics by DataKing99
• 8,100 points
24 views
0 votes
1 answer

What is the standard naming convention for the variables in R?

Use of period separator e.g. product.prices <- c(12.01, ...READ MORE

answered Apr 25, 2018 in Data Analytics by shams
• 3,580 points
18 views
0 votes
1 answer

What are the rules to define a variable name in R programming language?

A variable name in R programming language ...READ MORE

answered Sep 7, 2018 in Data Analytics by zombie
• 3,690 points
61 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
32 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
55 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
72 views
0 votes
1 answer

Plotting multiple graphs on the same page in R

If you want to plot 4 graphs ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,550 points
39 views
0 votes
1 answer

What are the important skills to have in Python with regard to data analysis?

The following are some of the important ...READ MORE

answered Aug 20, 2018 in Data Analytics by ANMOL
• 3,620 points
45 views
0 votes
1 answer

Which package is used to do data import in R and Python and How do you import SAS data?

We can do data import using multiple ...READ MORE

answered Aug 24, 2018 in Data Analytics by ANMOL
• 3,620 points
14 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.