Why is it not advisable to use attach in R and what should I use instead

0 votes
Let's pretend we have a data frame x with the columns employment and income in it. The commands x$job for the data in the job column and x$income for the data in the income column are typically used to refer to the data in the frame.

When referring to the same data, however, using the command attach(x) eliminates the need for the data frame's name and the $ symbol. As a result, in the R code, x$job becomes job and x$income becomes income.

The issue is that many R experts advise against using the attach() verb while programming in R.

What is the most important reason behind this? What should be substituted in its place?
Jun 10 in Data Science by Avinash
• 1,260 points
18 views

1 answer to this question.

0 votes
There is one more option that applies to both character and numeric data:

ux[which.max(tabulate(match(x, ux)))] mode - function(x) ux - unique(x) ux
That can produce a 10M-integer vector and determine its mode on my puny little PC in approximately 30 seconds.

The above method adopts the same strategy as which.max and delivers the first value of the set of modes if your data source is likely to have multiple modes. Use this variation (provided by @digEmAll in the comments) to return all modes:

Tabulate (match (x, ux)) ux[tab == max(tab)] Modes - function(x) - ux - unique(x)
}
answered Jun 24 by Sohail
• 2,960 points

Related Questions In Data Science

0 votes
0 answers

In R, how to get an object's name after it is sent to a function?

I'm trying to find the opposite of ...READ MORE

Jul 5 in Data Science by avinash
• 1,840 points
7 views
0 votes
0 answers

Standard Deviation in R Seems to be Returning the Wrong Answer - Am I Doing Something Wrong?

An easy illustration of standard deviation calculation: The ...READ MORE

Jun 30 in Data Science by avinash
• 1,840 points
21 views
0 votes
0 answers

How to use plotly in R shiny

I'm attempting to add a graph to ...READ MORE

Jul 20 in Data Science by avinash
• 1,840 points
9 views
0 votes
0 answers

Introduction to Statistical Learning with Applications in R Figure Codes

I recently bought the following book: An Introduction ...READ MORE

Jun 1 in Data Science by avinash
• 1,840 points
33 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
437 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,660 points
481 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,660 points
4,351 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

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

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

Difference between the == and %in% operators in R

percent in percent "returns a vector of ...READ MORE

answered Jun 20 in Data Science by Sohail
• 2,960 points
21 views
0 votes
1 answer

Difference between the == and %in% operators in R

According to help('percent in percent'), percent in ...READ MORE

answered Jun 23 in Data Science by Sohail
• 2,960 points
15 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP