## Data Handling Using R

gl() - Generate Factors

To generate factors we need some command - here factors means a category of things like small, medium, large or male , female

So, in R there is a command gl(), it helps generate factors by specifying the levels within

> gl(n = 3,k = 7,labels = c("om","namho","shivaya"),)

[1] om om om om om om om namho

[9] namho namho namho namho namho namho shivaya shivaya

[17] shivaya shivaya shivaya shivaya shivaya

Levels: om namho shivaya

to get in details further you can use help() function.

model.tables()

>model.tables(aov1,"means") #it will give means or other characteristic of a variable in a tabular format.

Make Data yourself

Suppose we want to make a data file where there are four columns as below

To generate factors we need some command - here factors means a category of things like small, medium, large or male , female

So, in R there is a command gl(), it helps generate factors by specifying the levels within

> gl(n = 3,k = 7,labels = c("om","namho","shivaya"),)

[1] om om om om om om om namho

[9] namho namho namho namho namho namho shivaya shivaya

[17] shivaya shivaya shivaya shivaya shivaya

Levels: om namho shivaya

to get in details further you can use help() function.

model.tables()

>model.tables(aov1,"means") #it will give means or other characteristic of a variable in a tabular format.

Make Data yourself

Suppose we want to make a data file where there are four columns as below

Here are the codes used to make the above result

>data<-data.frame(patients=1:100,

age=rnorm(100,34,6),

treatmenttype=gl(4,k = 25,labels = c("faaduu","classy","awesome","great"),ordered = F),

collegetype=sample(paste("college",LETTERS[5:10],sep = "@" ),100,replace = T))

##you can see for patients & age we use simple command but for treatment type & college type we used gl(), sample() & paste() commands, their learnings are essential which were discussed in earlier posts.

One can copy and paste the above code in R to generate the data.

xtab()- CrossTab- Making a contingency table

This command give a cross tabulation format depicting our variables in a tabular format

> xtabs(patients~treatmenttype+collegetype) #contingency table of patients w.r.t. treatmenttype & collegetype

>xtabs(~treatmenttype+collegetype) #contingency table between treatmenttype & collegetype

table() - contingency table using Frequency

it give frequency of the no. of each variable & it's type

> table(data$collegetype) # it give the no. of each "collegetype" in the dataset "data".

How to read various file format in R easy and fast

>data<-data.frame(patients=1:100,

age=rnorm(100,34,6),

treatmenttype=gl(4,k = 25,labels = c("faaduu","classy","awesome","great"),ordered = F),

collegetype=sample(paste("college",LETTERS[5:10],sep = "@" ),100,replace = T))

##you can see for patients & age we use simple command but for treatment type & college type we used gl(), sample() & paste() commands, their learnings are essential which were discussed in earlier posts.

One can copy and paste the above code in R to generate the data.

xtab()- CrossTab- Making a contingency table

This command give a cross tabulation format depicting our variables in a tabular format

> xtabs(patients~treatmenttype+collegetype) #contingency table of patients w.r.t. treatmenttype & collegetype

>xtabs(~treatmenttype+collegetype) #contingency table between treatmenttype & collegetype

table() - contingency table using Frequency

it give frequency of the no. of each variable & it's type

> table(data$collegetype) # it give the no. of each "collegetype" in the dataset "data".

How to read various file format in R easy and fast

read.clipboard() works on windows but not on Mac. For mac we use pipe(pbpaste) to read a file copied on clipboard.

To see the detail visit the pdf file

To see the detail visit the pdf file

How to read SPSS file format in R