[R] Beginner question: select cases

John Kane jrkrideau at yahoo.ca
Mon Sep 25 15:20:25 CEST 2006


--- Peter Wolkerstorfer - CURE <wolkerstorfer at cure.at>
wrote:

> Hello all,
> 
> I hope i chose the right list as my question is a
> beginner-question.
> 
> I have a data set with 3 colums  "London", "Rome"
> and "Vienna" - the
> location is presented through a 1 like this:
> London 	Rome 	Vienna	q1
> 0		0	1		4
> 0		1	0		2	
> 1		0	0		3
> ....
> ....
> ....
> 
> I just want to calculate the means of a variable q1.
> 
> I tried following script:
> 
> # calculate the mean of all locations
> results <- subset(results, subset== 1 )
> mean(results$q1)
> # calculate the mean of London
> results <- subset(results, subset== 1 ,
> select=c(London))
> mean(results$q1)
> # calculate the mean of Rome
> results <- subset(results, subset== 1 ,
> select=c(Rome))
> mean(results$q1)
> # calcualate the mean of Vienna
> results <- subset(results, subset== 1 ,
> select=c(Vienna))
> mean(results$q1)
> 
> As all results are 1.68 and there is defenitely a
> difference in the
> three locations I wonder whats going on.
> I get confused as the Rcmdr asks me to overwrite
> things and there is no
> "just filter" option.
> 
> Any help would be apprechiated. Thank you in
> advance.
> 
> Regards
> Peter


I'm new at R also.  However I don't recognize your
syntax. I have not seen select used here. 

Try 
results <- subset(results, London==1 )



More information about the R-help mailing list