Hi Tom,
I'm forwarding your questions to the list and I encourage everybody to send
questions such as these to the list. More than half the class are new R
users so it would be much better to send to the list than to send to Miya or
I individually. You should all send your questions regardless of how
"basic" you think they are because it is highly likely that there will be
more than a few people with the same questions.
On Tue, Feb 10, 2009 at 9:19 AM, Thomas Sander <tom_sander at harvard.edu>wrote:
Patrick --
A couple of questions:
1) I can't seem to figure out how to use the Histogram function. I tried
?Hist and didn't really understand the documentation, perhaps because I
don't have a clear sense of what par(mfrow=c(5,5)) is doing. Is there a
better place to look to understand examples of how to specify what it is
doing a histogram for 1.2.2 but I'm clearly missing something
I have
show<-par(mfrow=c(5,5))
for (i in 1:25) {
hist(show[i,])
}
The par(mfrow=c(5,5)) option tells R to plot 25 graphs in one window (5 rows
and 5 columns). It will then put the next 25 plots you specify into the
same window. So if you were trying to plot a histogram of each row of a
matrix called "mat", you would do something like this:
par(mfrow=c(5,5))
for(i in 1:25){
hist(mat[i,]
}
2) I can't seem to figure out how to load in the PS1_Data.
I set the wd to be where I keep the data and then loaded the data
setwd(dir="C:/Documents and Settings/tsander/My
Documents1/MDrivebkp/E2001")
load(PS1_Data)
I also tried load(PS1_Data.RData)
but in both cases, while it accepts the setwd command, it gives me an error
on the load command:
Error in load(PS1_Data.RData) : object "PS1_Data.RData" not found
Any advice?
A few people have been having trouble with this. I suspect it is related to
how your computer is reading RData files. I think if you load it directly
from the internet, it should work. Try this:
load(url("
http://isites.harvard.edu/fs/docs/icb.topic542875.files/Problem%20Set%201/P…
"))
You must be connected to the internet to load it, but once you load it, it
is on your R workspace and you do not need to be online. However, if you
close R, you would need to be online to load it again
unless you save your workspace.
3) finally, is there a command to count whether there are odd items in a
vector? I have kludgy code that sees whether the length of a vector divided
by 2 and then truncated is not equal to the lenth of a vector divided by 2,
but there must be a more elegant way to do this, and my code doesn't seem to
be working.
As far as I know, there is no nice prepackaged function to do this.
However, you can use the %% operation, also known as the modulo operation.
The modulo operation gives the remainder when dividing.
So 5 %% 2 gives 1. You can do something like length(vector) %% 2 == 0. If
TRUE, then your vector has an even number. If FALSE, then it has an odd
number.
Many thanks.
Best.
Tom
*Thomas Sander*
Executive Director
Saguaro Seminar: Civic Engagement in America
Harvard Kennedy School, Harvard University
79 JFK Street, Taubman 364, Cambridge, MA 02138
T - 617.496-2764 F - 617.495.1589
tom_sander at
harvard.edu
www.hks.harvard.edu/saguaro
new - socialcapitalblog <http://socialcapital.wordpress.com/>
*Please consider the environment before printing this e-mail*
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science,
Harvard University
http://www.people.fas.harvard.edu/~plam<http://www.people.fas.harvard.ed…