Skip to content

failing to select a subset of observations based on variable values [Sec: UNCLASSIFIED]

2 messages · Gosse, Michelle, David Winsemius

#
On Apr 26, 2010, at 3:39 PM, Gosse, Michelle wrote:

            
Did you read the help page for if?
?"if"
Leave behind your SPSS syntactical constructions. SPSS and the SAS  
data steps have implicit loops that operate sequantially along rows of  
datasets. R does not work that way. A corresponding operation in R  
might be:

  apply(dataframe1, 1, <function that works on a row of data>)

  "if" is a program control mechanism that does not operate on  
vectors. If it gets a vector if evaluates the first element and  
ignores the rest. (You should have gotten a warning and you should  
have posted the warning.)

There is also the ifelse function that works with and returns vectors.
?subset
?with

with(subset(dfrm, micronutrients[, 72] != 8 | micronutrients[, 73] !=  
8), table(...) )

Not sure what you intended with ... table(micronutrients[,8,80]) ... ,  
but generally one does not first reference an object with two  
dimensions and then do so with three. It is considered good form  
around these parts to offer at the very least str() on an object about  
which you are hoping to get specific advice. We cannot read your mind.
Do not see any code to which this refers. You can assign the result of  
the with(subset( ...), ... ) operation to an object on which you can  
do statistical tests, but table does not automatically do chi-square  
test. Maybe you should look at summary.table() or xtabs()
David Winsemius, MD
West Hartford, CT