Blog Archives

Applying Same Changes to Multiple Dataframes

March 28, 2012
By
Applying Same Changes  to Multiple Dataframes

How to apply the same changes to several dataframes andsave them to CSV: # a dataframea <- data.frame(x = 1:3, y = 4:6)# make a list of several dataframes, then apply function (change column names, e.g.):my.list <- list(a, a)my.list <- lapply(...

Read more »

How to Extract Citation from a Body of Text

March 26, 2012
By
How to Extract Citation from a Body of Text

Say, you have a text and you want to retrieve the cited names and years of publication. You wouldn't want to this by hand, wouldn't you?Try the following approach:(the text sample comes from THIS freely available publication)library(stringr)(txt <- ...

Read more »

Classification Trees and Spatial Autocorrelation

March 25, 2012
By
Classification Trees and Spatial Autocorrelation

I'm currently trying to model species presence / absence data (N = 523) that were collected over a geographic area and are possibly spatially autocorrelated. Samples come from preferential sites (sea level > 1200 m, obligatory presence of permanent ...

Read more »

Custom Summary Stats as Dataframe or List

March 24, 2012
By
Custom Summary Stats as Dataframe or List

On Stackoverflow I found this useful example on how to apply custom statistics on a dataframe and return the results as list or dataframe:somedata<- data.frame(               ...

Read more »

Creating a Stratified Random Sample of a Dataframe

March 14, 2012
By
Creating a Stratified Random Sample of a Dataframe

Expanding on a question on Stack Overflow I'll show how to make a stratified random sample of a certain size: d <- expand.grid(id = 1:35000, stratum = letters)p = 0.1dsample <- data.frame()system.time(for(i in levels(d$stratum)) { dsub <...

Read more »

R-Function to Read Data from Google Docs Spreadsheets

March 13, 2012
By
R-Function to Read Data from Google Docs Spreadsheets

I used this idea posted on Stack Overflow to plug together a function for reading data from Google Docs spreadsheets into R. google_ss <- function(gid = NA, key = NA) { if (is.na(gid)) {stop("\nWorksheetnumber (gid) is missing\n")} if (is....

Read more »

Apprentice Piece with Lattice Graphs

February 28, 2012
By
Apprentice Piece with Lattice Graphs

Lattice graphs can be quite tedious. I don't use them too often and  when I need them I usually have to dig the archives for the parameter-details.The here presented example may serve as a welcome template for the usage of panel functions, panel o...

Read more »

Testing the Effect of a Factor within each Level of another Factor with R-Package {contrast}

February 27, 2012
By
Testing the Effect of a Factor within each Level of another Factor with R-Package {contrast}

This is a small example of how custom contrasts can easily be applied with the contrast-package. The package-manual has several useful explanations and the below example was actually grabbed from there.This example can also be applied to a GLM but I ch...

Read more »

Transformation of Several Variables in a Dataframe

February 1, 2012
By
Transformation of Several Variables in a Dataframe

This is how I transform several columns of a dataframe, i.e., with count-data into binary coded data (this would apply also for any other conversion..).count1

Read more »

A Short Example with R-Package osmar..

January 26, 2012
By
A Short Example with R-Package osmar..

Following up my last post in which I praised the capabilities of the osmar-package I give a short example...ps: You can also find this example at GitHub HERE.library(osmar) # this pulls the data from the OSM-Api:mydistrict <- get_osm(relation(85647)...

Read more »