Syntax

R Apply a Function Syntax

In R, apply a function: applies a function to each element — sapply(v, function(x) x * 2)

Quick Answer

Syntax
sapply(v, function(x) x * 2)
RSyntax

Apply a Function

Code example
sapply(v, function(x) x * 2)

Applies a function to each element.

Learn More

How to apply a function in R

  1. Open your R file or editor.
  2. Copy the example, then replace its sample names and values for your code.

R Apply a Function Syntax

Use sapply(v, function(x) x * 2).

Related Syntax References

Frequently asked questions

What is the R syntax for apply a function?

Use this pattern: sapply(v, function(x) x * 2)

Can I copy this R code example?

Yes. Use Copy code and adapt the example to your program.

Is this R syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify