Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace df <- df %>% ... with a shortcut

Tags:

r

magrittr

I guess most of us have already used something like this (at least if you are using the tidyverse):

library(tidyverse)

example <- mtcars
example <- example %>%
  select(- mpg)

My question: I know there is a shortcut for this part:

example <- example %>% ...

But I can neither remember nor find it on Google.

I think it was something similar to this %<>%.

Can anyone help?

Please excuse me if this question was already asked before.

Best regards

like image 813
KevR Avatar asked Jun 05 '20 06:06

KevR


People also ask

How to replace values in Data Frame?

Suppose that you want to replace multiple values with multiple new values for an individual DataFrame column. In that case, you may use this template: df['column name'] = df['column name']. replace(['1st old value','2nd old value',...],['1st new value','2nd new value',...])

How to replace a specific value in pandas?

replace() function is used to replace values in column (one value with another value on all columns). This method takes to_replace, value, inplace, limit, regex and method as parameters and returns a new DataFrame. When inplace=True is used, it replaces on existing DataFrame object and returns None value.

How to replace column values in a DataFrame?

In order to replace a value in Pandas DataFrame, use the replace() method with the column the from and to values.


1 Answers

This lhs %<>% rhs from the magrittr package. So in your case example %<>% select(- mpg)

like image 69
Dominik S. Meier Avatar answered Oct 23 '22 04:10

Dominik S. Meier