Working with factors and numbers


#working with factors
>data=c(1,2,3,2,2,3,1,1,3,4,4,3)
>fdata=factor(data)
>fdata
>table (fdata)

#assigning label to a factor variable
>rdata=factor(data,labels=c('I','II','III','IV'))
>rdata
>table (rdata)
#Example using retinol data>retinol$tabac=factor(retinol$tabac, labels=c("Never", "Ex", "Current"))


#transforming an object into factor is necessary so that R treats it as a categorical variable

varname=as.factor(varname)


#transforming string to numeric

names=c("donald", "mickey", "pluto")
names_fact=as.factor(names)
names_fact
names_num=as.numeric(names_fact)
names_num



Introduction to the Analysis of Survival Data in the Presence of Competing Risks

 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4741409/