Analysis of tabular data from csv file

[This article was first published on Krishna's R Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Sometimes data may not be available in the csv file in the required format. Consider the following csv file, whose details are as follows – Four different treatments were given to four different groups of patients. Random samples of size 7 were selected from each group and blood levels of Hb percentage levels were measured after one month. The objective is to test whether there are significant differences in the mean values of the Hb percentage levels due to treatments by the application of one-way ANOVA.

The following is the csv file containing the patients treatments data.
treatments-rawdata1

Method :

1.Read the csv file and convert it as a matrix “trt”. Next extract the four rows of the matrix and convert them into vectors.
2.Create a list and subsequently using stack() function convert this list into a dataframe “df”.
3. The above stack function creates the dataframe df with two columns ind and values. ind is a categorical variable(factors) and values variable contain the Hb percentage levels. Rename the column ind as “Treatments” and perform one-way ANOVA.

The results are given below :

anova-results

The complete code is given below :

anovacode

 

 

To leave a comment for the author, please follow the link and comment on their blog: Krishna's R Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)