http://www.sfu.ca/immr/pmp/people.htm
Michael is currently a faculty member in the School of Engineering Science
at Simon Fraser University teaching courses related to technical writing,
group dynamics, graphical communication, and ethics and law.nique Process Feaures
Just a collection of some random cool stuff. PS. Almost 99% of the contents here are not mine and I don't take credit for them, I reference and copy part of the interesting sections.
Friday, October 8, 2010
Tuesday, October 5, 2010
Ruby create a class object with name determined at runtime, calling dynamic methods
http://ruby-doc.org/docs/ProgrammingRuby/html/ospace.html
Calling a method unknown during compile time.
So we want to call a method but we only get the method's name at runtime, use the 'send' method
ruby-1.8.7-p302 > 'John Coltran'.send('length')
=> 12
or using 'method' to call it later
or 'eval'
r = eval "'John Coltran'.length"
=> 12
-------------------------------------
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/190828
$ irb
ruby-1.8.7-p302 > b=Object::const_get('String').new()
=> ""
ruby-1.8.7-p302 > b
=> ""
ruby-1.8.7-p302 > b.class
=> String
# Print all User tuples
> b = Object::const_get('User').new()
> puts b.class
=> String
> puts b.class.all
#
$ rails console < my_script_helper.rb
--------class----------------
vs
--------module-------------
http://ruby-doc.org/core/classes/Module.html
A Module is a collection of methods and constants.
Calling a method unknown during compile time.
So we want to call a method but we only get the method's name at runtime, use the 'send' method
ruby-1.8.7-p302 > 'John Coltran'.send('length')
=> 12
or using 'method' to call it later
or 'eval'
r = eval "'John Coltran'.length"
=> 12
-------------------------------------
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/190828
$ irb
ruby-1.8.7-p302 > b=Object::const_get('String').new()
=> ""
ruby-1.8.7-p302 > b
=> ""
ruby-1.8.7-p302 > b.class
=> String
# Print all User tuples
> b = Object::const_get('User').new()
> puts b.class
=> String
> puts b.class.all
#
# The Greeter class
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
# Create a new object
g = Greeter.new("world")
# Output "Hello World!"
g.salute
module Mod
alias_method :orig_exit, :exit
def exit(code=0)
puts "Exiting with code #{code}"
orig_exit(code)
end
end
include Mod
exit(99)
Monday, October 4, 2010
R blogs and gallery
http://addictedtor.free.fr/graphiques/ http://www.statmethods.net/input/missingdata.html# create new dataset without missing data
newdata <- na.omit(mydata)
Reshaping data
# example of melt function
library(reshape)
mdata <- melt(mydata, id=c("id","time")) # Creating a Graph with a linear model regression line
attach(mtcars)
plot(wt, mpg)
abline(lm(mpg~wt))
title("Regression of MPG on Weight")
# Filled Density Plot
d <- density(mtcars$mpg)
plot(d, main="Kernel Density of Miles Per Gallon")
polygon(d, col="red", border="blue") Comparing Groups VIA Kernal Density
The sm.density.compare( ) function in the sm package allows you to superimpose the kernal density plots of two or more groups. The format is sm.density.compare(x, factor) where x is a numeric vector and factor is the grouping variable.# Compare MPG distributions for cars with
# 4,6, or 8 cylinders
library(sm)
attach(mtcars)
# create value labels
cyl.f <- factor(cyl, levels= c(4,6,8),
labels = c("4 cylinder", "6 cylinder", "8 cylinder"))
# plot densities
sm.density.compare(mpg, cyl, xlab="Miles Per Gallon")
title(main="MPG Distribution by Car Cylinders")
# add legend via mouse click
colfill<-c(2:(2+length(levels(cyl.f))))
legend(locator(1), levels(cyl.f), fill=colfill) http://yihui.name/en/page/2/
http://yihui.name/en/2009/06/creating-tag-cloud-using-r-and-flash-javascript-swfobject/#more-224 - Tag Cloud
Side by side plot
# png(width = 500, height = 300)x = rep(0, 1000)par(mfrow = c(1, 2), mar = c(4, 4, 0.1, 0.1))plot(density(x), main = "")plot(density(x), main = "")rug(jitter(x))# dev.off()
# transparent colors (alpha = 0.1)plot(x, col = rgb(0, 0, 0, 0.1))http://processtrends.com/RClimate.htm ## Use regexp to replace all the occurences of **** with NA
lines2 <- gsub("\\*{3,5}", " NA", lines, perl=TRUE)## Select monthly data in first 13 columns df <- df[,1:13]
## Remove rows where Year=NA from the dataframe df <- df [!is.na(df$Year),]
Sunday, October 3, 2010
Using lattice in R
http://www.his.sunderland.ac.uk/~cs0her/Statistics/UsingLatticeGraphicsInR.htm
## Multiple variables in formula for grouped displays
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width | Species,
data = iris, scales = "free", layout = c(2, 2),
auto.key = list(x = .6, y = .7, corner = c(0, 0))) ## user defined panel functions
states <- data.frame(state.x77,
state.name = dimnames(state.x77)[[1]],
state.region = state.region)
xyplot(Murder ~ Population | state.region, data = states,
groups = state.name,
panel = function(x, y, subscripts, groups)
ltext(x = x, y = y, label = groups[subscripts], cex=1,
fontfamily = "HersheySans")) http://learnr.wordpress.com/2009/08/18/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13/
http://data.princeton.edu/R/gettingStarted.html
http://www.r-bloggers.com/5-minute-analysis-in-r-case-shiller-indices/
http://lmdvr.r-forge.r-project.org/figures/figures.html
Lucid update Ubuntu splash in grub
http://anonir.wordpress.com/2010/08/08/ubuntu-lucid-disable-boot-splash/
Open
For example, if your grub has this line:
Change it to this:
Then run this command to update grub2:
Open
/etc/default/grub for editing and remove “quiet splash” options from the GRUB_CMDLINE_LINUX_DEFAULT property.For example, if your grub has this line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"Change it to this:
GRUB_CMDLINE_LINUX_DEFAULT=""Then run this command to update grub2:
sudo update-grub
R removing NA
http://www.opensubscriber.com/message/r-help@stat.math.ethz.ch/7268077.html
> df<-data.frame(name=c('a','b'), age=c('1','2'))
> if (any(apply(df,1,function(x) any(is.na(x)))) == TRUE) { r <- df[-which(apply(df,1,function(x) any(is.na(x)))),] } else { r <- df }
> r
name age
1 a 1
2 b 2
> df<-data.frame(name=c('a','b'), age=c('1',NA))
> df
name age
1 a 1
2 b
> if (any(apply(df,1,function(x) any(is.na(x)))) == TRUE) { r <- df[-which(apply(df,1,function(x) any(is.na(x)))),] } else { r <- df }
> r
name age
1 a 1
> df<-data.frame(name=c('a','b'), age=c('1','2'))
> if (any(apply(df,1,function(x) any(is.na(x)))) == TRUE) { r <- df[-which(apply(df,1,function(x) any(is.na(x)))),] } else { r <- df }
> r
name age
1 a 1
2 b 2
> df<-data.frame(name=c('a','b'), age=c('1',NA))
> df
name age
1 a 1
2 b
> if (any(apply(df,1,function(x) any(is.na(x)))) == TRUE) { r <- df[-which(apply(df,1,function(x) any(is.na(x)))),] } else { r <- df }
> r
name age
1 a 1
## Remove rows where Year=NA from the dataframe df <- df [!is.na(df$Year),]
Saturday, October 2, 2010
tm package on R
R 2.11 is needed by tm (tm_0.5-4.1.tar.gz) but only R 2.10 is in the lucid ubuntu repo
so
http://ubuntuforums.org/showthread.php?t=639710
deb http://cran.r-project.org/bin/linux/ubuntu lucid/
so
http://ubuntuforums.org/showthread.php?t=639710
deb http://cran.r-project.org/bin/linux/ubuntu lucid/
gpg --keyserver subkeys.pgp.net --recv-key E2A11821 gpg -a --export E2A11821 | sudo apt-key add -
My R libraries installed to
$HOME/R/x86_64-pc-linux-gnu-library/2.11
So you need to add this path in the 'R console' Run configuration
then I got a 'checking for xml2-config... no' error when doing
install.packages('XML')so do
$ sudo apt-get install libxml2-dev
Ubuntu 10.04.1 LTS Lucid Lynx
#enable canonical archive in /etc/apt/sources.list
sudo apt-get install sun-java6-jdk
sudo apt-get install r-base
sudo apt-get install sun-java6-jdk
sudo apt-get install r-base
sudo apt-get update && sudo apt-get install cairo-dock cairo-dock-plug-ins
Ubuntu Intrepid AMD64
https://launchpad.net/ubuntu/intrepid/amd64
/var/lib/dpkg$ sudo cp status-old2 status
/var/lib/dpkg$ sudo cp status-old2 status
Friday, October 1, 2010
/usr/bin/ld: cannot find -lgfortran
$ ld -lgfortran
ld: cannot find -lgfortran
$ sudo ln -s /usr/lib/libgfortran.so.3.0.0 /usr/lib/libgfortran.so
$ ld -lgfortran
ld: warning: cannot find entry symbol _start; not setting start address
ld: cannot find -lgfortran
$ sudo ln -s /usr/lib/libgfortran.so.3.0.0 /usr/lib/libgfortran.so
$ ld -lgfortran
ld: warning: cannot find entry symbol _start; not setting start address
School, Life, Lessons
" The difference between school and life? In school, you're taught a lesson and the given a test. In life, you're given a test that teaches you a lesson" - Tom Bodett
Subscribe to:
Posts (Atom)