Jeremy,
Glad this was helpful.
? basically we want to choose the data points for which plomin[,11] is NA
or 0, but not 1. Is there a way of doing this via subset - or do we need to
recode the data?
You can simply do this using:
& (is.na(plomin[,11])=T | plomin[,11])==0)
Then the but not 1 part is redundant.
Hth,
Jens
From: gov2001-l-bounces at
lists.fas.harvard.edu
[mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Jeremy Hodgen
Sent: Tuesday, March 25, 2008 5:42 PM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] SPSS data
Jens
Thanks for this. Clearly no need for a loop but the data does behave very
oddly - I don't know why the logical expression doesn't work in the code
that we had - the only reason that I can see is that plomin[,11] has missing
data whereas the other two do not.
However, your code does seem to work - except that in this case, we do want
to keep the missing data in - so basically we want to choose the data points
for which plomin[,11] is NA or 0, but not 1. Is there a way of doing this
via subset - or do we need to recode the data?
Jeremy
On 25 Mar 2008, at 17:42, Jens Hainmueller wrote:
Jill,
Are you trying to create a subset of the data for which variable 7=0,
variable 3=1, and variable 11= 0 or 1?
In that case there is no need for a lop. You just do:
subset <- plomin[,7]==1 & plomin[,3]==0 & (plomin[,11]==1 | plomin[,11]==0)
subset will be a logical vector that has length n. it will be equal to true
if all three conditions are true. Use this to subset the data.
sub.plomin <- plomin[subset,]
think about how this treats missing values.
Jens
-----Original Message-----
From: gov2001-l-bounces at
lists.fas.harvard.edu [mailto:gov2001-l-
bounces at
lists.fas.harvard.edu] On Behalf Of Jill Hohenstein
Sent: Tuesday, March 25, 2008 1:34 PM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] SPSS data
Thanks for your quick reply!
Sorry, the line really read like this:
if (plomin[i,7] == 1 & plomin[i,3] == 1 & plomin[i,11] == 0)
That was my cut & paste error from trying out many different solutions!
Cheers,
Jill
On 25/03/2008 17:31, "Oliver Craig Bevan" <bevan at fas.harvard.edu>
wrote:
This may not fix it, but it seems as though you have an extra (or
missing)
bracket:
##
if (plomin[i,7] == 1) & plomin[i,3] == 1 & plomin[i,11] == 0 )
##
the bracket at the end of the line does not seem to close an earlier
one.
Hope
this helps a little.
Hi all,
We are working on our replication project and have loaded an SPSS
file into
R. We are attempting to select rows based on values of three
variables. The
first two have values of 1 and 2. We can easily select for the value
of 1.
The third variable has values of 0 and 1. When we try to select for
any
value (either 0 or != 1), we get an error message that reads:
Error in if (plomin[i, 11] == TRUE) { :
missing value where TRUE/FALSE needed
This is what our code looked like:
vec <- c()
k <- 0
for(i in 1:nrow(plomin)){
if (plomin[i,7] == 1) & plomin[i,3] == 1 & plomin[i,11] == 0 )
{
k <- k + 1
vec[k] <- i}
}
mat.corr.gesl <- plomin[vec,c(20,21)]
Does anyone have any idea why we should be getting this message? Or,
alternatively, is there a better way of selecting for values of our
variables?
Thanks!
Best wishes,
Jill and Jeremy (Hodgen)
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
--
Graduate Student
Department of Government
Harvard University
Cambridge, MA
_______________________________________________
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
Dr Jeremy Hodgen
Senior Lecturer in Mathematics Education
King's College London
Department of Education and Professional Studies
Franklin-Wilkins Building
Waterloo Bridge Wing
150 Stamford Street
London SE1 9NH
Tel: 020 7848 3102
Fax: 020 7848 3182
E-mail: jeremy.hodgen at kcl.ac.uk