Question

Program R Please write about the difference between the assignment operators <- and <<- ? You...

Program R

Please write about the difference between the assignment operators <- and <<- ? You need to refer to help(assignOps) for this answer.

Homework Answers

Answer #1

There are three different assignment operators: two of them have leftwards and rightwards forms.

The operators <- assign into the environment in which they are evaluated. The operator <- can be used anywhere.

The operators <-  can be used, almost interchangeably, to assign to variable in the same environment.

The operators <<- is normally only used in functions, and cause a search to be made through parent environments for an existing definition of the variable being assigned. If such a variable is found (and its binding is not locked) then its value is redefined, otherwise assignment takes place in the global environment. Note that their semantics differ from that in the S language, but are useful in conjunction with the scoping rules of R. See ‘The R Language Definition’ manual for further details and examples.

The <<- operator is used for assigning to variables in the parent environments (more like global assignments). The rightward assignments, although available are rarely used.

First, let’s look at an example.

x <- rnorm(100)
y <- 2*x + rnorm(100)
lm(formula=y~x)

The above code uses both <- and = symbols, but the work they do are different. <- in the first two lines are used as assignment operator while = in the third line does not serves as assignment operator but an operator that specifies a named parameter formula for lm function.

In other words, <- evaluates the the expression on its right side (rnorm(100)) and assign the evaluated value to the symbol (variable) on the left side (x) in the current environment. = evaluates the expression on its right side (y~x) and set the evaluated value to the parameter of the name specified on the left side (formula) for a certain function.

We know that <- and = are perfectly equivalent when they are used as assignment operators.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This question is about the C program(NOT C++ program) Please write the C program to find...
This question is about the C program(NOT C++ program) Please write the C program to find out the largest and the smallest number in 32bits For example ,the smallest number in 32 bits is -2147483648
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 + 3 + 4 + … 9 + 10 + 11 + 12, and return the answer. However, you’ll be using two different methods to do this. The first method should utilize either a for loop or...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
Assignment Objectives: Understand the difference between metrics and analytics. Describe which characteristics of HR metrics and...
Assignment Objectives: Understand the difference between metrics and analytics. Describe which characteristics of HR metrics and workforce analytics are most likely to have an organizational impact. Purpose: This assignment will help you understand and HR metrics and analytics, and discuss the differences between metrics and analytics for HR efficiency, and operational effectiveness.   Assignment Description: To complete this written assignment, you will need to read chapter six of the text and access the PDF file entitled: “Data Analytics in Human Resources:...
Write a Java program to get the difference between the largest and smallest values in an...
Write a Java program to get the difference between the largest and smallest values in an array of integers. The length of the array must be 1 and above
This assignment asks you to write a paper (1 page) about transactional leadership, more specific the...
This assignment asks you to write a paper (1 page) about transactional leadership, more specific the CONTINGENT REWARD. Please support your ideas
Please write a program that reads the file you specify and calculates how many times each...
Please write a program that reads the file you specify and calculates how many times each word stored in the file appears. However, ignore non-alphabetic words and convert uppercase letters to lowercase letters. For example, all's, Alls, alls are considered to be the same words. What is the output of the Python program when the input file is specified as "proverbs.txt"? That is, in your answer, include the source codes of your word counter program and its output. <proverbs.txt> All's...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Write a program that generates a vector with 30 random integers between –10 and 20 and...
Write a program that generates a vector with 30 random integers between –10 and 20 and then finds the maximum of all the elements that are divisible by 3. if you can explain how you got to finding the maximum it well help. also please use matlab
i want solved problem or example about STEEL PILE FOUNDATION, to write in my assignment, i...
i want solved problem or example about STEEL PILE FOUNDATION, to write in my assignment, i mean i have to write an assignmment about steel pile foundation i just need a example or solved problem about steel pile, please answer with a good hand writing which be clear to read and just about steel pile foundation NOT about other pile foundations JUST STEEL PILE
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT