[R] Basic SPSS commands in R ?
Thomas Lumley
tlumley at u.washington.edu
Mon Sep 10 17:28:08 CEST 2001
On Sat, 8 Sep 2001, C. Schulz wrote:
> Hello,
> i'm newbie of R and think it is a really good alternative to SPSS.
> But i have more problems using elementary things comparable with using advanced methods.
>
> (1) How can i value label i.e the variable X in data.frame DATA
> with the labels ( 1=very good ) (2=good).
>
> spss syntax when DATA is in Spreadsheet is:
> value labels X
> 1 'very good'.
> 2 'good'.
> execute.
x<-factor(x,labels=c("very good","good"))
> (2) How can i split the data set dependent from one variable and
> give a special output i.e. frequencies.
>
> spss syntax:
> SORT CASES BY countryg .
> SPLIT FILE
> LAYERED BY countryg .
> FREQUENCIES
> VARIABLES=X Y Z
> /ORDER ANALYSIS .
>
Various commands. The easiest is by(), tapply is more general
For example, looking at the Cars93 dataset in the MASS package:
library(MASS) #load the package
data(Cars93) #load the dataset
#summaries of all variables by type of car
by(Cars93,Cars93$Type,summary)
##summaries of weight, horsepower and engine size by US/Foreign origin
by(Cars93[,c("Weight","Horsepower","EngineSize")],Cars93$Origin,summary)
## table of no. of cylinders by type for US and Foreign cars.
by(Cars93[,c("Cylinders","Type")], Cars93$Origin, table)
This also gives some more examples of factors (aka VALUE LABELS)
-thomas
Thomas Lumley Asst. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list