Skip to content
Prev 308952 / 398503 Next

Defining categories

Hi,
?(Jorge: Thanks for the suggestion.)
cut? will be much easier.

dat1<-read.table(text="
2.880556
0.616667
5.083333
0.858333
0.466667
2.936111
4.258333
0.258333
2.033333
2.583333
1.088889
0.447222
1.872222
0.080556
4.033333
4.116667
1.633333
2.147222
",sep="",header=FALSE)
?dat1$Categ<-cut(dat1$V1,breaks=c(0,1,2,3,4,5,6))
#Either

library(car) 
dat1$Categ<-recode(dat1$Categ,"'(0,1]'=1;'(1,2]'=2;'(2,3]'=3;'(3,4]'=4;'(4,5]'=5;'(5,6]'=6")
#or
dat1$Categ<-as.numeric(gsub(".*\\,(\\d+).*","\\1",dat1$Categ))
#formats the Categ column.
head(dat1)
#??????? V1 Categ
#1 2.880556???? 3
#2 0.616667???? 1
#3 5.083333???? 6
#4 0.858333???? 1
#5 0.466667???? 1
#6 2.936111???? 3
A.K.