Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Create an Expression in R Programming - expression() Function
Next article icon

Repeatedly Evaluate an Expression in R Programming - replicate() Function

Last Updated : 30 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
replicate() function in R Language is used to repeatedly evaluate a function or expression. It is member of apply family in R base package. In this article, we'll learn syntax and implementation of replicate() function with the help of examples.
Syntax: replicate(n, expr, simplify) Parameters: n: represents number of times the expression has to be evaluated expr: represents expression simplify: represents logical value. If TRUE, output is represented in vector or matrix form, otherwise in a list form
Example 1: r
# Set the seed set.seed(10)  # Generate random numbers with mean = 0 and sd = 1 x <- rnorm(5, mean = 0, sd = 1)  # Print print(x)  # Evaluating it repeatedly r <- replicate(n = 3, rnorm(5, 0, 1), simplify = FALSE )  # Print print(r) 
Output:
  [1]  0.01874617 -0.18425254 -1.37133055 -0.59916772  0.29454513    [[1]]  [1]  0.3897943 -1.2080762 -0.3636760 -1.6266727 -0.2564784    [[2]]  [1]  1.1017795  0.7557815 -0.2382336  0.9874447  0.7413901    [[3]]  [1]  0.08934727 -0.95494386 -0.19515038  0.92552126  0.48297852  
Example 2: r
# Output to be present as PNG file png(file = "replicateGFG.png")  # Set the seed set.seed(10)  # Replicate values and create histogram hist(replicate(100, mean(rexp(10))))  # Saving the file dev.off() 
Output:

Next Article
Create an Expression in R Programming - expression() Function
author
utkarsh_kumar
Improve
Article Tags :
  • R Language
  • R Math-Function

Similar Reads

  • Evaluate an Expression in R Programming - eval() Function
    eval() function in R Language is used to evaluate an expression passed to it as argument. Syntax: eval(expr) Parameters: expr: expression to be evaluated Example 1: # R program to evaluate an expression # Calling eval() Function eval(sin(pi / 3)) eval(5 + 2) eval(cos(2)) Output: [1] 0.8660254 [1] 7
    1 min read
  • Evaluating an Expression in R Programming - with() and within() Function
    with() function in R programming evaluates the expression in an environment constructed locally by the data and does not create a copy of the data. Syntax: with(data, expr) Parameters: data represents dataset to be used expr represents formula or expression to be evaluated Example 1: # Creating list
    2 min read
  • Create an Expression in R Programming - expression() Function
    expression() function in R Language is used to create an expression from the values passed as argument. It creates an object of the expression class. Syntax: expression(character) Parameters: character: Expression, like calls, symbols, constants Example 1: # R program to create an expression # Calli
    1 min read
  • Modify Data of a Data Frame with an Expression in R Programming - with() Function
    with() function in R Language is used to modify data of a data frame by evaluating an expression within the arguments of the function. Syntax: with(x, expr) Parameters: x: Data frame expr: Expression to modify data Example 1: # R program to modify data of an object # Calling predefined data set BOD
    1 min read
  • Create Repetitions of a String in R Programming - strrep() Function
    strrep() Function in R Language is used to create specified number of repetitions of a specified string. Syntax: strrep(string, n) Parameter: string: specified string n: number of repetitions Example 1: # R Program to illustrate # the use of strrep function # String to be repeated x <- "Geek
    1 min read
  • Replace values of a Factor in R Programming - recode_factor() Function
    Factors in R programming are kind of data structures that stores categorical data i.e., levels and can have any type of data (integer, string, etc). recode_factor() function in R Language is used to replace certain values in a factor. To use recode_factor() function, dplyr package is required. Synta
    1 min read
  • Creating a Vector of sequenced elements in R Programming - seq() Function
    In This article, we will discuss how we Create a Vector of sequenced elements in R Programming Language using seq() Function. What are sequenced elements?Sequenced elements mean things that are placed in a particular order, one after another. This concept is often used in various fields. seq() Funct
    2 min read
  • Assigning values to variables in R programming - assign() Function
    In R programming, assign() method is used to assign the value to a variable in an environment. Syntax : assign(variable, value) Return : Return the variable having value assigned. Example 1: # Using assign() method assign("gfg", 10) print(gfg) Output: [1] 10 Example 2: # Using assign() met
    1 min read
  • Recursively apply a Function to a List in R Programming - rapply() function
    rapply() function in R Language is used to recursively apply a function to a list. Syntax: rapply(object, f, classes = "ANY", deflt = NULL, how = c("unlist", "replace", "list")) Parameters: object: represents list or an expression f: represents function to be applied recursively classes: represents
    3 min read
  • Remove Duplicate Elements from an Object in R Programming - unique() Function
    unique() function in R Language is used to remove duplicated elements/rows from a vector, data frame or array. Syntax: unique(x) Parameters: x: vector, data frame, array or NULL Example 1: # R program to illustrate # unique function # Initializing some set of numbers x <- c(1:10, 5:9) x # Calling
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences