Hi Abby,
A cool trick someone taught me recently to grab all but one column in the matrix is to use
the minus sign. For example, if data is your matrix, and you wanted to grab all but the
first column, use:
data[,-1]
will be equivalent to:
data[,2:ncol(data)]
This was helpful in simplifying my code
Best regards
Joseph
Joseph Poj Gavinlertvatana
Doctoral student, Marketing
Harvard Business School
203 Wyss Hall, Soldiers Field, Boston, MA 02163
Ph?? 617.230.5907
Fx 617.496.4397
Txt/Vm 617.910.0563
Em pgavinlertvatana at
hbs.edu
-----Original Message-----
From: gov2001-l-bounces at
lists.fas.harvard.edu [mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Maya Sen
Sent: Sunday, February 28, 2010 1:59 PM
To: Class List for Gov 2001/E-2001
Subject: Re: [gov2001] loading the data
HI Abby,
So the data are saved as a matrix, which means that you can't use the
"$" (what you use with data frames). You could save the data as a data
frame by doing something like
data <- data.frame(data)
but you actually need the data to be in matrix form in order to do the
matrix multiplication command %*%, so just be careful with that.
hope that helps,
Maya
On Sun, Feb 28, 2010 at 1:56 PM, Abigail Coplin
<abigail.coplin at gmail.com> wrote:
Hey Miya and all,
I didn't have any problem loading the data, but I keep getting error msgs
when I try to use the $ operator to call up individual columns...I can ?only
call them using their number. ?Any ideas how to fix this problem? It would
make my code a little nicer.
Best, Abby
On Sat, Feb 27, 2010 at 8:57 PM, Maya Sen <msen at fas.harvard.edu> wrote:
Hey all,
Some of you have asked about loading the data for pset4. Once you've
saved the data in your working directory and executed the "load"
command, you should type in ls() in your R console. This will let you
see everything that R currently has stored in its workspace. If you
successfully loaded the data, then you'll see an object called "data",
which are the data for the problem set.
If you use Windows, you can actually double click on the
"presidential.RData" icon and that will automatically open up R with
the data already in the workspace.
hope that helps -
Maya
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l