Rkward (the GUI for the statistical package - R ) is a great FOSS program offered to those who choose to fly linux :). I've started using it again because it's that time of year again, where field report data needs testing. And yet again, it's time to read up on the R-project documentation, not to mention all the Rkward documentation...
There are many additional packages that are offered with Rkward, so many that the scroll bar moves about 20 lines with a small movement with the mouse. Crazy, I know. The
R-project website is a very useful place and I picked up the complete manual and it is sitting on my desktop. It is about 3500 pages long, but very useable with a littler know how and the 'Find' function.
What may be unknown about R, is that much of it (the best parts) uses code. And what is good about that? Well I'm not sure yet, though I think I have an idea. I'll try and keep this post 'Open' and edit it with useful code for the R CLI. Enjoy!
Install Packages
For some reason, I always have trouble using the GUI to install packages. Workaround, use the CLI. Running rkward as sudo may also help, but not required.
> install.packages()
A window will come up and your package/s should be listed. It will download, and install the package in one go. Don't forget to load the package if you need to use it. In the R CLI, type:
> library(package.name)
Useful packages
So here is a list of the packages which I have installed on my system. These do not come installed with an R package:
-> car
-> hexbin
-> sm
-> reshape
-> sp
-> vegan
-> googleVis
-> rgl
-> zoo
-> chron
-> ggplot2
-> ecodist
NB:
googleVis is an awesome package!!
To install all of the packages listed above in one go, execute:
> install.packages(c("car","hexbin","sm","reshape","sp","vegan","googleVis","rgl","zoo","chron","ggplot2","ecodist"))
Assigning data from data.table
Rkward comes with a neat way to handle data. Once Rkward is running, you can create a new data table to enter data in cell. This may not always be the best method, but this is how you store columns from that data table to a variable, ie x. This is so you can then perform various tasks comparing 2 or more of the columns of your dataset. On the CLI:
> x <- my.data[1]
>
y <- my.data[2]
Unlike a typical computer language, R begins counting from 1 and so my.data[1] will be the first column, my.data[2] will be the second and so on. You can now call the column of data simply by typing the variable into CLI.
However, this method doesn't seem to work when you call the vectors for use in a function...
Scatterplot with regression line
These can be graphed from x,y dataset either by the GUI or the CLI. CLI is like this:
>
plot(y ~ x, data=my.data)
Then to plot a fit line using the lm() method:
>
abline(lm(y~x, data=my.data), col="red")
It will show up on the graph automatically.
Coefficients of scatterplot regression line (from above)
Print out the coefficients of the regression line:
>
variable <- lm(y~x, data=my.data)
As per above, variable can be anything you want. Something more relevant is useful, ie. fit, coefs, interp etc.
Linux distribution
It came to my attention that R may very well run better on certain Linux distributions. I'm in the process of doing a clean install and am curious at this idea. I have opted for Ubuntu Server ed amd64 after being convinced that this package while being supplemented with R dependencies, is not bundled with process hog applications. I'll see how it pans out.
Emacs
So not only have I installed a light-weight yet powerful distro, I've found some useful information about using R with Emacs. Here's some helpful links to get you started:
1)
Emacs commands/shortcuts - just a few of the >1000 available
2)
Post by a user on how to load an .R file
Links and places to check out
http://www.statmethods.net/index.html
http://lmdvr.r-forge.r-project.org/figures/figures.htm
http://r.789695.n4.nabble.com/Best-64-bit-Linux-distro-for-R-td881882.html - a rather recent discussion is being held here about the best Linux distro to run R on
http://cran.r-project.org/bin/linux/ubuntu/ Good guide to CLI installation of R