%>% 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,610 points
49 views

3 answers to this question.

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
0 votes
%>% is called a pipe. The process of using pipe is called piping.

Piping is generally used to avoid intermediate variable creation.

It helps in faster execution and easier understanding of opeartions.

A pipe genrally follow below structure -

dataset %>% function1(dataset/list/vector) %>% function2(dataset/list/vector) %>% . . . . . .  

Which follows the operation as output of function1 to function2 and so on..
answered Aug 6 by anonymous

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,130 points
297 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,130 points
38 views
0 votes
1 answer

What are the top packages in R for data visualization?

These are the top R packages used ...READ MORE

answered Aug 25 in Data Analytics by Cherukuri
• 31,840 points
18 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
33 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
74 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
172 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
120 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
59 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
93 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
40 views