EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer
Physics
C.S.

Unix Shell R Code Practice Workshop --II

#####################################
2nd section on Saturday afternoon
#first need to go the correct directory
cd python-data
ipython notebook: open a window browser to run python code, take some time
more tutorial for numpy at: http://swcarpentry.github.io/python-novice-inflammation/01-numpy.html

#######################################
3rd section on Sunday Morning
def(): define function and remember to call

ipython notebook: to run python from notebook

import pandas

cd ..

!pwd : need to use ! for the command in notebook

!head -4 A1_mosquito_data.csv

More tutorial at: 
http://software-carpentry.org/v5/intermediate/python/01-intro-python.html

##running stats. regression model:

import statsmodels.api as sm

regr_results=sm.OLS.from_formula('mosquitos ~ temperature', data).fit()
regr_results.summary()
regr_results.params['Intercept']

line_fit =regr_results.params['Intercept'] +\
regr_results.params['temperature']*data['temperature']
##use \ to continue another line, or just use ()

something useful:
R: sqldf forum: https://groups.google.com/forum/?fromgroups#!forum/sqldf
https://code.google.com/p/batchfiles/
customize startup in R: http://cran.r-project.org/doc/contrib/Lemon-kickstart/

##4th section for version control #very useful tutorial from the following: http://software-carpentry.org/v5/novice/git/01-backup.html
cd to home directory
mkdir git/
cd git/

#set up global confituation:
$ git config --global user.name "Firstname Last"
$ git config --global user.email "user@email.com"
$ git config --global color.ui "auto"
$ git config --global core.editor "nano"

cd           # return to home directory
mkdir alpha  # make a new directory alpha
cd alpha     # go into alpha
git init     # make the alpha directory a Git repository
mkdir beta   # make a sub-directory alpha/beta
cd beta      # go into alpha/beta
git init     # make the beta sub-directory a Git repository


#########################################################
http://software-carpentry.org/v5/novice/shell/04-loop.html
Shell 2: Files and Directories
pwd: print current working directory
ls: list current folder contents
ls -F: tags folders with /  (distinguishes between files and directories)
ls -la #display files with size and permission information
cd: change folder
cd . : change folder to parent directory
cd - : change folder to the last (previous) directory you were in
 
Shell 3: Creating Things
http://software-carpentry.org/v5/novice/shell/02-create.html
nano: 
for example: nano filename.txt
CTRL-x to exit nano
CTRL-o to save the text file
Removing files:
rm: remove file, there is no trash bin!
rmdir: remove directory, only if it is empty.
rm -r: recursive delete: will delete a directory and everything in it.
Copying and moving:
mv [from] [to]: move, can move multiple files 
cp [source] [to dir]: copy
cp -r [source] [to dir]: copy recursively (copies everything inside)
Up and down arrow keys let you scroll through your history of commands
Home directory is denoted ~, e.g. cd ~

Shell 4: Pipes and filters
http://software-carpentry.org/v5/novice/shell/03-pipefilter.html
General structure: filter-pipe-filter-pipe-...-filter
wc: word count
Output: three columns: # lines / # words / # characters / filename
wc -l # output the number of lines
wc -m # output the number of characters
   
Related links:
Continue to Small but Powerful R Tips --I   SAS Interview

Back to R code practice in Unix Shell Whorkshop-I   Analytics Home