Learn R Programming

cwhmisc (version 4.0)

lengths.angle: Lengths of two vectors and angle between them.

Description

Compute lengths of two vectors and the angle between them.

Usage

lengths.angle(x, y)

Arguments

x
the first vector. Alternatively, a single matrix with both vectors as columns can be provided.
y
the second vector, optional if x is an appropriate structure.

Value

  • A list with elements
  • lxthe length of x.
  • lythe length of y.
  • anglethe angle (in radian) between x and y.
  • angleDegthe angle (in degrees) between x and y.

Examples

Run this code
x <- c(1,2,2,-1)
	y <- c(0,0.1,3,2)
  (l <- lengths.angle(x, y))  # == lengths.angle(cbind(x, y))
#> $lx    #> [1] 3.16228
#> $ly    #> [1] 3.60694
#> $angle #> [1] 1.1937
l$angle/pi*180 # in degrees  >  68.394

Run the code above in your browser using DataLab