coords.data.frame: Create a new data.frame with a given coordinate system

Description Usage Arguments Value Examples

View source: R/Conversion.R

Description

This does not affect the original object unless new coordinate system is directly assigned.

Usage

1
2
## S3 method for class 'data.frame'
coords(x, new.coords, ...)

Arguments

x

a data.frame with columns labelled x, y, z (for cartesian) or theta, phi (for spherical colatitude and longitude respectively)

new.coords

specifies the new coordinate system ("spherical" or "cartesian").

...

Unused arguments.

Value

A new data.frame whose coordinates are as specified by new.coords

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Create df with no coords, then create df2 with spherical coords
df <- data.frame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1))
df

df2 <- coords(df, new.coords = "spherical")
df2


## The function coords does not affect the original object.
## To change the coords assign a new value ("spherical or "cartesian")

coords(df, new.coords = "spherical")
df
coords(df) <- "spherical"
df

rcosmo documentation built on Feb. 14, 2020, 5:06 p.m.