This file contains hidden or 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
# Ways to execute a shell script in Ruby | |
# Example Script - Joseph Pecoraro | |
cmd = "echo 'hi'" # Sample string that can be used | |
# 1. Kernel#` - commonly called backticks - `cmd` | |
# This is like many other languages, including bash, PHP, and Perl | |
# Returns the result of the shell command | |
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |
This file contains hidden or 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
<<child-demo, child='methods.rnw', eval=TRUE>>= | |
@ | |
### | |
#### Put this in the child document to identify the parent: |
This file contains hidden or 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
require(reshape2) | |
dcast(pds2,codeyear~lparty,length,value_var="codeyear")->tmp | |
# the codeyear variable is the row identifier. use this to remerge back into the dataset |
This file contains hidden or 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 liklihood of a Poission Distribution | |
exp(-theta*length(data))*theta^sum(data))/prod(factorial(data) | |
(factorial(n)/(factorial(k)factorial((k-n))))p^k * (1-p)^(n-k) |
This file contains hidden or 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
my_input=File.open("my_input.txt","r") # load some file as type: File | |
fixb=Hash.new | |
fixb.merge! "\t" => "&", | |
"\n"=>"\\\\"+"\\\\"+"\n", | |
"\""=>"" | |
my_output=my_input.read.to_s | |
fixb.each_pair do |key, val| | |
my_output.gsub!(key,val) |
This file contains hidden or 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
# Display pretty color pallete: | |
RColorBrewer::display.brewer.pal(5,"Set1") | |
# Get the hex values for the color palette | |
RColorBrewer::brewer.pal(5,"Set1") | |
# set these to names that you can use later. Ex: | |
red<-"#E41A1C" | |
blue<-"#377EB8" |
This file contains hidden or 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
mysearch <- function (OBJ,searchterm="year") { | |
p<-ls(OBJ)[grep(searchterm,ls(OBJ))] | |
return(p) | |
} |
This file contains hidden or 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
sapply(names(ds2),function(x){ | |
eval(substitute(class(ds2$x),env=list(x=x))) | |
}) |
This file contains hidden or 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
myfun <- function(x) deparse(substitute(x)) | |
# so myfun(myQOG) will give output "myQOG" |
This file contains hidden or 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
paste("ds2$",names(ds2)[1],sep="")->x | |
eval(parse(text=(x))) # will output the contents of the object name constructed in x, in this case, it will output the individual names of all cases in a dataset. |
OlderNewer