Hi, everyone.
Kate had some good questions. For a program template, look at Zelig,
Chapter 6, Section 2.1. For those of you who find this oenerous, the
program looks like this:
check <- function(p, q) {
result <- (p-q)/q
result
}
check(4, 5) # or check(p = 4, q = 5)
Several things to note:
* The curly braces {} enclose the commands that the program will perform.
* The parentheses () are to define the arguments that go into the function
(or for mathematical operations, as in line 2).
* The <- stores symbols. So line 1 stores the function as check (we run
the function by typing check and the arugments), but the second arrow in
line 2 stores information only within the function itself (you can't find
results once you exit the function), so you have to make sure that you
return the function's output in the last line of the function (as in line
3).
* When writing code, more spaces are better -- this makes your code
readable.
* Please comment your code so I know what's going on. If your function
bombs but you comment your code, you will get partial credit.
* If you want to check your OLS function, you can use zelig(...., model =
"ls").
On Kate's second question, you can use any text editor (Notepad, Wordpad,
Microsoft Word), but this makes formatting your code more difficult. One of
the neat things about XEmacs is that it highlights your braces and indents
your code so you can see where you're going wrong.
Also, I discovered that the set up on the course web site for Windows XEmacs
lets you export your graphics to a file that you can put in a Word document,
if you don't want to use latex. If you go through the process of setting up
Windows XEmacs, you'll still learn to use R properly, but you'll be able to
use Word (until you learn TeX).
Keep the questions coming. 8)
Yours, Olivia
----- Original Message -----
From: "Kate Emans" <emans(a)fas.harvard.edu>
To: <olau(a)fas.harvard.edu>
Sent: Friday, September 24, 2004 3:32 PM
Subject: request for simple program example
Hi Olivia!
1) I've been pondering R and trying to filter all the information. I
think (and I suspect others will agree) that it is not too hard to figure
out how to use individual commands. But it is difficult w/ out knowing R
set-up, what is the basic syntax for a simple "program."
I'm wondering if you could send us an example, sort of a template, for a
very simple R program that we could use as an example? Of course I don't
want you to give away how to do anything in the prob set, so it could be a
program that does something simple: like make two matricies and multiply
them. But I think it would really help just to see the basic set up from
start to finish of a simple program and what exactly this looks like; what
are the good basic commands to start and end with and how do they string
together. THis is hard to get from the manual.
2) Also, a specific question: can we use any text editor to create a
program of R commands? Obviously learning Emacs is desirable but if we
can't do it quite yet, will any text editor work, or just that one?
THanks very much for your help. I send this to you and not hte whole list
so if you think question one is unreasonable you will not be pressured to
do it! But if you answer you can send to the whole list along w/ my
question.
:) Kate