as.data.frame: Converts an object of class '"SoilProfileCollection"' to a...

Description Usage Arguments Details Note Author(s) See Also Examples

Description

Converts an object of class "SoilProfileCollection" to an object of class "data.frame" with both site and horizon data sorted in one row. Each original column name in the horizons table receives a sufix *_A, B, ..., Z where alphabetic letters represent horizon sequence.

Usage

1
2
## S4 method for signature 'SoilProfileCollection'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

x

object of class "SoilProfileCollection"

row.names

character; giving the row names for the data frame (missing values are not allowed)

optional

logical; if ‘TRUE’, setting row names and converting column names (to syntactic names: see ‘make.names’) is optional

...

optional arguments

Details

The advantage of converting the "SoilProfileCollection" data to a single table is that, once both tables have been merged to a single data frame, it can be more easily exported and visualized in a GIS and/or imported into a data base.

Note

Few profiles with a large number of horizons can make the whole data frame become large. Consider removing such locations or aggregating measured values per horizon to a lower number of horizons.

Author(s)

Tomislav Hengl and Brendan Malone

See Also

as.geosamples, mpspline

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(aqp)
library(plyr)
library(rgdal)
library(sp)
## sample profile from Nigeria:
lon = 3.90; lat = 7.50; id = "ISRIC:NG0017"; FAO1988 = "LXp" 
top = c(0, 18, 36, 65, 87, 127) 
bottom = c(18, 36, 65, 87, 127, 181)
ORCDRC = c(18.4, 4.4, 3.6, 3.6, 3.2, 1.2)
## prepare a SoilProfileCollection:
prof1 <- join(data.frame(id, top, bottom, ORCDRC), 
    data.frame(id, lon, lat, FAO1988), 
    type='inner')
depths(prof1) <- id ~ top + bottom
site(prof1) <- ~ lon + lat + FAO1988 
coordinates(prof1) <- ~ lon + lat
proj4string(prof1) <- CRS("+proj=longlat +datum=WGS84")
## convert to a simple table:
x <- as.data.frame(prof1)
str(x)
## horizons only
horizons <- getHorizons(x, idcol="id", sel=c("top", "bottom", "ORCDRC"))
horizons

Example output

GSIF version 0.5-5.1 (2019-01-04)
URL: http://gsif.r-forge.r-project.org/
This is aqp 1.25

Attaching package:aqpThe following object is masked frompackage:stats:

    filter


Attaching package:plyrThe following objects are masked frompackage:aqp:

    mutate, summarize

Loading required package: sp
rgdal: version: 1.5-18, (SVN revision 1082)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
Path to GDAL shared files: /usr/share/gdal
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: /usr/share/proj
Linking to sp version:1.4-4
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
Joining by: id
'data.frame':	1 obs. of  28 variables:
 $ id      : chr "ISRIC:NG0017"
 $ lon     : num 3.9
 $ lat     : num 7.5
 $ FAO1988 : chr "LXp"
 $ top_A   : num 0
 $ bottom_A: num 18
 $ ORCDRC_A: num 18.4
 $ hzID_A  : chr "1"
 $ top_B   : num 18
 $ bottom_B: num 36
 $ ORCDRC_B: num 4.4
 $ hzID_B  : chr "2"
 $ top_C   : num 36
 $ bottom_C: num 65
 $ ORCDRC_C: num 3.6
 $ hzID_C  : chr "3"
 $ top_D   : num 65
 $ bottom_D: num 87
 $ ORCDRC_D: num 3.6
 $ hzID_D  : chr "4"
 $ top_E   : num 87
 $ bottom_E: num 127
 $ ORCDRC_E: num 3.2
 $ hzID_E  : chr "5"
 $ top_F   : num 127
 $ bottom_F: num 181
 $ ORCDRC_F: num 1.2
 $ hzID_F  : chr "6"
            id top bottom ORCDRC
1 ISRIC:NG0017   0     18   18.4
2 ISRIC:NG0017  18     36    4.4
3 ISRIC:NG0017  36     65    3.6
4 ISRIC:NG0017  65     87    3.6
5 ISRIC:NG0017  87    127    3.2
6 ISRIC:NG0017 127    181    1.2

GSIF documentation built on May 2, 2019, 5:44 p.m.

Related to as.data.frame in GSIF...