Skip to contents

This function adds two objects. If both objects are numeric vectors, it performs element-wise addition. If one or both objects are strings, it concatenates them. For other objects, it attempts to use the + method defined for the class of the objects.

Usage

add(x, y)

Arguments

x

An object.

y

An object.

Value

The result of adding the two objects.

Examples

# Add two numeric vectors
add(c(1, 2, 3), c(4, 5, 6))
#> [1] 5 7 9
# Concatenate two strings
add("hello", "world")
#> [1] "helloworld"
# Add a number and a string (concatenation)
add(1, " world")
#> [1] "1 world"