Storing numeric vectors (or arrays) in fields of an R data frame

To store variable-length data vectors and corresponding single-value data in separate fields of the same row of an R data frame, add a new modeless column then populate it:

> bar$cwidth <- NA 
> emptyrow <- data.frame(matrix(rep.int(NA,length(bar)),ncol=length(bar))) 
> names(emptyrow) <- c("abund","cwidth") 
> bar <- rbind(bar,emptyrow) 
> bar$abund[3] <- 3 
> bar$cwidth[3] <- list(c(6,0.3,4)) 
> str(bar)
'data.frame': 3 obs. of  2 variables:
$ abund : num  3 4 3
$ cwidth:List of 3
..$ : logi  NA
..$ : logi  NA
..$ : num  6 0.3 4
>

R recognizes that the vector’s class is numeric, but it is necessary to store it as mode list. If the column were mode array, then the dimension would have to be fixed across all rows of the data frame, and therefore not the best fit for irregular data. It is possible to store each vector as array, though; just create and rbind the new row, then populate with the array as list:

> bar$cwidth[nrow(bar)] <- list(as.array(c(6,0.3,4))) 
> str(bar)
'data.frame': 3 obs. of  2 variables:
$ abund : num  3 4 3
$ cwidth:List of 3
..$ : logi  NA
..$ : logi  NA
..$ : num [1:3(1d)] 6 0.3 4
>
Posted in data munging, R | Tagged , , , ,

Quick-and-dirty coastal habitat characterization, part 4: Salt marshes

Fourth and final post on coastal habitat characterization for the Northwest Atlantic: salt marshes. Provides a starting point for a more detailed narrative and application of modifiers. All factors used here are after Knox (2001) and Bertness (2007):

1) Marsh maturity

  • young
  • middle-aged
  • mature

2) Elevation

  • low
  • intermediate
  • high

3) Physical stressors (tides, sediment supply, storms, ice, etc.)

  • low
  • moderate
  • high

4) Anthropic stressors (ditching, dredging, dyking, grazing, fires, etc.)

  • low
  • moderate
  • high
Posted in coastal ecology, habitat characterization, marine ecology, salt marshes, western atlantic

rgdal on Mac OS X: reprise

After successful installation of rgdal on a Mac, trying again on an older MacBook Pro running OS X 10.5 (Leopard). Upgraded to the latest R (2.13.1), and followed all of my previous steps. But on “R CMD INSTALL…” got an error telling me that the compiler couldn’t build executables. So assumed that I needed a newer compiler and tried to find the last version of XCode to run on Leopard. No luck. Gave-in and took the time to upgrade to Snow Leopard (10.6) and accompanying XCode. Then tried the rgdal install again. Success! But wait: tried require(rgdal) in R64.app, as before, but getting errors about rgdal not being for x86_64, and rgdal is not available, etc. So tried R.app (the i386 app) — and it worked. 

Assume the difference is between R 2.11 and 2.13, or that initial R install was on OS X 10.5. Regardless, it seems that the most important thing is to get rgdal to cleanly build from source. Then just use the R app that works.

Posted in os x, packages, R

Quick-and-dirty coastal habitat characterization, part 3: Man-made structures

Apart from artificial reefs, could not find substantive information on other types of infrastructure in general texts on coastal ecology; so for this post relying on a recent review paper, and the perspectives of contributers to Sea Grant databases. Characterization of man-made structures:

1) Structure type

  • breakwater
  • groin/jetty
  • bulkhead/seawall/abutment
  • structural support (dock piling, bridge pier, wharf pile, etc.)
  • floating dock
  • fishing/aquaculture gear (cages, nets, poles, ropes, etc.)

2) Elevation

  • persistently at/near sea surface (e.g. a floating dock)
  • above mean high water, spring tides
  • mean high water, spring tides
  • mean high water
  • mean tide level
  • mean low water
  • mean low water, spring tides
  • subtidal

3) Wave Stress

  • wave exposed
  • moderately wave exposed
  • wave sheltered

4) Tidal stress

  • high tidal flow (strong currents)
  • moderate tidal flow (moderate/varying currents)
  • low tidal flow (weak currents)

Forthcoming post: salt marshes.

Posted in coastal ecology, habitat characterization, man-made structures, marine ecology, western atlantic

Quick-and-dirty coastal habitat characterization, part 2: Soft shores

Second post on coastal habitat characterization, specific to the Northwest Atlantic. Rocky coasts were outlined in part one. Here, soft-sediment shores:

1) Type/Community (Raffaelli, 1996Mann, 2000Bertness, 2007)

  • reflective beach (steep slope, coarse sand, low wave energy)
  • intermediate beach (moderate or varying slope, varying sediment size, varying wave energy)
  • dissipative beach (low slope, fine sand, high wave energy)
  • tidal flat
  • oyster reef
  • seagrass bed

2) Elevation (Raffaelli, 1996; Knox, 2001; Bertness, 2007)

  • dry or drying sand (completely dry at low tide)
  • damp sand (capillary retention at low tide)
  • wet/permanently saturated (water table or no circulation through sediment)

3) Tidal stress (Raffaelli, 1996; Bertness, 2007)

  • high tidal flow (strong currents)
  • moderate tidal flow (moderate/varying currents)
  • low tidal flow (weak currents)

Forthcoming posts: salt marshes and man-made structures.

Posted in coastal ecology, habitat characterization, marine ecology, soft-sediment shores, western atlantic | Tagged , , , ,

rgdal on Mac OS X

This was a bit of a headache to get right. Here’s what worked on OS X 10.6.7 (Snow Leopard, i386 architecture, R version 2.12.2):

1) Download the “GDAL Complete” framework from http://www.kyngchaos.com/software/frameworks and install.

2) Open R, and on the startup panel in preferences, make sure the “Add ~/Library/R…” is checked (enables user-level install).

3) Use the R package installer (in Packages & Data menu) to install the sp package. CRAN binaries can be used, but select “at user level” for install location.

4) Download the rgdal package source from CRAN to a local drive.

5) Open Terminal, cd to the directory containing the rgdal source *.tar.gz file (e.g. rgdal_0.6-33.tar.gz), and install with the following command: R CMD INSTALL –configure-args=’–with-gdal-config=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config –with-proj-include=/Library/Frameworks/PROJ.framework/unix/include –with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib’ rgdal_0.6-33.tar.gz

One thing to note is that the R64.app must be used even on an i386 architecture.

UPDATE: SEE SUBSEQUENT POST ON INSTALLATION ON OLDER MACHINES; AND THE ISSUE OF WHICH APP TO USE.

And in R…

> require(rgdal)
Loading required package: rgdal
Loading required package: sp
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.8.0, released 2011/01/12
Path to GDAL shared files: /Library/Frameworks/GDAL.framework/Versions/1.8/Resources/gdal
Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009
Path to PROJ.4 shared files: (autodetected)
>

Posted in os x, packages, R | Tagged , ,

Starfish!

Asterias forbesi

Asterias forbesi or A. rubens? A. forbesi has a bright orange madreporite (“f-orange-besi”).

Actually easier to remember now, as A. rubens was recently determined a synonym of the accepted taxonomic name, Echinaster (Echinaster) sepositus (Retzius, 1783)

Posted in marine biology | Tagged , , , ,