Assigning global variables from inside a function - R

0 votes
I know that i can use the global variables declared outside a function, but is there a way to declare global variables from inside a function?
May 15, 2018 in Data Analytics by DataKing99
• 8,240 points
10,073 views

1 answer to this question.

+1 vote

You can assign global variables from inside the function using "<<-"  operator.

Let me demonstrate that using this example:

abc<-function(){
  num1<<-10
  print(num1)
}
num1
[1] 10
answered May 15, 2018 by Bharani
• 4,660 points

Related Questions In Data Analytics

0 votes
1 answer

R programming: How to pass variables from a r program to mysql function?

To include the R variables called start.date and end.date, you can use paste to ...READ MORE

answered Dec 28, 2018 in Data Analytics by Tyrion anex
• 8,700 points
1,008 views
0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,740 points
2,289 views
0 votes
2 answers

R function for finding the index of an element in a vector?

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

answered Dec 12, 2020 in Data Analytics by Rajiv
• 8,910 points
55,964 views
0 votes
5 answers

How to remove NA values from a Vector in R?

Hello team, you can use na.omit x <- c(NA, 3, ...READ MORE

answered Dec 9, 2020 in Data Analytics by anonymous
• 82,880 points
191,496 views
0 votes
1 answer

How to set global variables in R

To set global variables, you can use ...READ MORE

answered Apr 24, 2018 in Data Analytics by kappa3010
• 2,090 points
991 views
0 votes
1 answer

How to remove all variables except functions in R?

One line that removes all objects except for functions: rm(list ...READ MORE

answered Apr 25, 2018 in Data Analytics by DeepCoder786
• 1,720 points
3,604 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
720 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
805 views
0 votes
1 answer

Extracting numeric columns from a data.frame - R

You can use the select_if() function from ...READ MORE

answered May 4, 2018 in Data Analytics by Bharani
• 4,660 points
7,507 views
0 votes
1 answer

Discarding duplicate rows from a data.frame - R

You can use distinct() function along with ...READ MORE

answered May 4, 2018 in Data Analytics by Bharani
• 4,660 points
497 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP