This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n <- 50 | |
m <- 50 | |
set.seed(1) | |
mu <- -0.4 | |
sig <- 0.12 | |
x <- matrix(data=rlnorm(n*m, mu, sig), nrow=m) | |
library(fitdistrplus) | |
## Fit a log-normal distribution to the 50 random data set | |
f <- apply(x, 2, fitdist, "lnorm") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## The following example demonstrates | |
## how a serach and replace string task | |
## can be peformed with R across several files | |
## Create two text files with content | |
filenames <- c( tempfile(), tempfile() ) | |
for( f in filenames ){ | |
cat("We wish you a Merry Christmas!\n\nBest regards\n", file=f) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Response to | |
## http://r-ecology.blogspot.com/2011/12/weecology-can-has-new-mammal-dataset.html | |
## Code from R-ecology | |
# URLs for datasets | |
comm <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_communities.csv" | |
refs <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_references.csv" | |
sites <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_sites.csv" | |
spp <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_species.csv" | |
trap <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_trapping.csv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setwd("/Mac/R_stuff/Blog_etc/Mammal_Dataset") | |
# URLs for datasets | |
comm <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_communities.csv" | |
refs <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_references.csv" | |
sites <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_sites.csv" | |
spp <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_species.csv" | |
trap <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_trapping.csv" | |
# read them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setwd("/Mac/R_stuff/Blog_etc/Mammal_Dataset") | |
# URLs for datasets | |
comm <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_communities.csv" | |
refs <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_references.csv" | |
sites <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_sites.csv" | |
spp <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_species.csv" | |
trap <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_trapping.csv" | |
# read them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Copyright 2012 Markus Gesmann | |
### markus dot gesmann at gmail dot com | |
### | |
### This file is made available under the terms of the GNU General Public | |
### License, version 2, or at your option, any later version, | |
### incorporated herein by reference. | |
### | |
### This program is distributed in the hope that it will be | |
### useful, but WITHOUT ANY WARRANTY; without even the implied | |
### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(XML) | |
library(googleVis) | |
url <- "http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating" | |
page <- readLines(url) | |
gvisCountryRating <- function(rating.agent="S&P", which=3, | |
startRating=4, page=page){ | |
x <- readHTMLTable(page, which=which) | |
levels(x$Rating) <- substring(levels(x$Rating), startRating, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Markus Gesmann, January 2012 | |
## Please install the following R packages first: | |
## data.table, doBy, plyr, reshape, sqldf, e.g. via | |
## install.packages(c("data.table", "doBy", "plyr", "reshape", "sqldf")) | |
f <- function(x) x^2 | |
sapply(1:10, f) | |
do.call("rbind", as.list( | |
by(iris, list(Species=iris$Species), function(x){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Markus Gesmann, February 2012 | |
## This R script requires the googleVis package, | |
## a browser with Flash and an Internet connection. | |
gvisWeeklyStockData <- function(tckr = "AAPL", | |
chartid ="Apple", | |
start.year=1984){ | |
require(googleVis) | |
d <- Sys.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Copyright Markus Gesmann, March 2011 | |
## Distributed under GPL 2 or later | |
## Animated Geo Charts based on ideas and code by: | |
## Manoj Ananthapadmanabhan and Anand Ramalingam | |
## Here we animate the life expectancy by country from 1960 | |
## This demo requires the 'WDI' and 'Hmisc' packages | |
library(WDI) | |
library(Hmisc) |