How to create a function in R?

0 votes

Hi Team,

I am new to R. I have configured Rstudio. I want to create a Function in R. How can I do that?

Oct 29 in Data Analytics by akhtar
• 32,960 points
21 views

1 answer to this question.

0 votes

Hi@akhtar,

We can create user-defined functions in R. They are specific to what a user wants and once created they can be used as the built-in functions. Below is an example of how a function is created and used.

new.function <- function(a) {
   for(i in 1:a) {
      b <- i^2
      print(b)
   }
}
answered Oct 29 by MD
• 77,580 points

Related Questions In Data Analytics

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,720 points
1,084 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,720 points
1,268 views
0 votes
1 answer

How to create a box-plot using “plotly” in R?

You can use this command to create ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,720 points
3,085 views
0 votes
1 answer

How to create a new R6 Class in R?

You have to first create an object ...READ MORE

answered Jul 5, 2018 in Data Analytics by DataKing99
• 8,210 points
402 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,720 points
223 views
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
1,615 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
122 views
0 votes
1 answer

How to create a list in R?

Hi@akhtar, A list is an R-object that can ...READ MORE

answered Oct 28 in Data Analytics by MD
• 77,580 points
24 views
0 votes
1 answer

How to create a pie chart in R?

Hi@akhtar, In R the pie chart is created ...READ MORE

answered Oct 29 in Data Analytics by MD
• 77,580 points
15 views