Analysis of tabular data from csv file

November 15, 2016

(This article was first published on Krishna's R Blog, and kindly contributed to R-bloggers)

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.

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 :


The complete code is given below :




To leave a comment for the author, please follow the link and comment on their blog: Krishna's R Blog. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)