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.
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 :