Question

In: Computer Science

R programming language. The seafood data recorded the bacterial growth on oysters and mussels. The bacterial...

R programming language.

The seafood data recorded the bacterial growth on oysters and mussels. The bacterial counts are measured in log scale at three different times.


Convert the data to have one variable showing the bacterial counts and one variable showing the different time points.

Seafood time0 time1 time2
Oysters 1.83 3.68 5.23
Oysters 1.11 3.25 4.98
Oysters 2.01 3.98 5.02
Oysters 7.19 7.42 9.32
Oysters 6.89 7.34 8.92
Oysters 7.01 8.11 9.99
Oysters 6.47 9.44 9.78
Oysters 5.98 8.77 9.88
Oysters 5.45 8.12 9.35
Mussels 0.36 1.70 4.57
Mussels 0.76 1.65 4.52
Mussels 0.56 1.55 4.23
Mussels 5.01 6.38 7.95
Mussels 5.00 6.87 7.99
Mussels 5.03 6.42 8.01
Mussels 5.05 9.78 11.04
Mussels 5.89 9.99 11.35
Mussels 5.97 9.86 11.22

Solutions

Expert Solution

Hey,
For answering this one I have used tidyr library package in my program.
The "tidyr" library has a function named gather() which can be used in reshaping data frames from wide format to long format.

A Brief description:
For an example, say a data which is considered unstacked and a common attribute of concern is spread out across columns. To reformat the data such that these common attributes are gathered together as a single variable, the gather() function will take multiple columns and collapse them into key-value pairs, duplicating all other columns as needed.

HERE COMES THE WORKING CODE FOR YOU (with comments for your understandibility) :-

library(tidyr) #loading the tidyr package
#defining the original data
data <- data.frame(Seafood = c("Oysters", "Oysters", "Oysters", "Oysters", "Oysters", "Oysters", "Oysters", "Oysters", "Oysters", "Mussels" ,"Mussels", "Mussels", "Mussels", "Mussels", "Mussels", "Mussels", "Mussels", "Mussels"), # Create example data frame
time0 = c(1.89, 1.11, 2.01, 7.19,6.89,7.01,6.47, 5.98, 5.45, 0.36, 0.76, 0.56, 5.01, 5.00, 5.03, 5.05, 5.89, 5.97),
time1 = c(3.68, 3.25, 3.98, 7.42,7.34,8.11,9.44, 8.77, 8.12, 1.70, 1.65, 1.55, 6.38, 6.87, 6.42, 9.78, 9.99, 9.86),
time2 = c(5.23, 4.98, 5.02, 9.32,8.92,9.99,9.78, 9.88, 9.35, 4.57, 4.52, 4.23, 7.95, 7.99, 8.01, 11.04, 11.35, 11.22))
data$Seafood <- as.character(data$Seafood) #First column is a character type
data$time0 <- as.numeric(data$time0) #All the time columns(time0, time1, time2) are of numeric type
data$time1 <- as.numeric(data$time1)
data$time2 <- as.numeric(data$time2)   
print("The Original Data::\n")
data #printing the original data frame

mod_DF <- gather(data,TimeStamp, BacteriaCount, time0:time2) #using gather function to convert the original data variables and storing the reshaped data in mod_DF
print("The Resultant Modified Data with Bacteria Counts and DIfferent Time Stamps::\n")
mod_DF #printing the resultant reshaped data frame



OUTPUT WINDOW:
Since the resultant data frame is long i.e. having 54 rows so I have to paste the output snapshots in 3 parts.


SNAP 1:


SNAP 2:


SNAP 3:


Hope this is helpful, Have a great day!!! :)


Related Solutions

Researchers are investigating the effect of storage temperature on bacterial growth for two types of seafood....
Researchers are investigating the effect of storage temperature on bacterial growth for two types of seafood. They set up the experiment to evaluate 3 storage temperatures. There were 9 storage units that were available, and so they randomly selected 3 storage units to be used for each storage temperature, and both seafood types were stored in each unit. After 2 weeks, bacterial counts were made. After taking a logarithmic transformation of the counts, they produced the following ANOVA: Type 3...
In the R programming language, we would like to use the data set called iris to...
In the R programming language, we would like to use the data set called iris to build a simple linear regression model to predict Sepal.Length based on Petal.Length. Calculate the least squares regression line to predict Sepal.Length based on Petal.Length. Interpret the slope of the line in the context of the problem. Remember that both variables are measured in centimeters. Plot the regression line in a scatterplot of Sepal.Length vs. Petal.Length. Test H1: ??1 ≠ 0 at ?? = 0.05...
This questions was asked to be done using R language programming. The datasets are available along...
This questions was asked to be done using R language programming. The datasets are available along with MASS package in Rstudio. A. Package ‘MASS’ which provides a description of the datasets available in the MASS package Then, complete the following analysis of the identified data from the library. B. One-sample t-test: Use the “chem” dataset to answer the question, “is the flour production company producing whole meal flour with greater than 1 part per million copper in it?” C. Two-sample...
R programming language A) Create a function that accepts two arguments, an integer and a vector...
R programming language A) Create a function that accepts two arguments, an integer and a vector of integers. It returns the count of the number of occurrences of the integer in the input vector. 1]Input: num_count <-function ??? 2]Input: num_count(2,c(1,1,2,2,3,3)) 2] Output: 2 3] Input: num_count(1,c(1,1,2,2,3,1,4,5,5,2,2,1,3)) 3] Output : 4 B) Create a function that accepts 3 integer values and returns their sum. However, if an integer value is evenly divisible by 3, then it does not count towards the...
1.What is the relationship between the LSD and a Z score? (R programming Language) Write a...
1.What is the relationship between the LSD and a Z score? (R programming Language) Write a fragment of code comparing how both would be computed. Use the Z score for the standard error of a mean, $z_i = (x_i - \mu)/(\sigma / \sqrt(n))$ 2. How would you modify the calculations of LSD to produce Tukey's Honest Signficant Difference?
Discuss the advantages and disadvantages of R programming language in the health care industry. Discuss applications...
Discuss the advantages and disadvantages of R programming language in the health care industry. Discuss applications of R for data analysis and visualization. Discuss three R statements used for decision making. Include three corresponding example statements. Describe two data visualization options in R programming language. Provide an example of a health care data application for each of the visualization options selected (for example, histogram). What is the purpose of the Microsoft Visual Studio? List the commands used to create a...
Use R programming language to answer and please so show the code as well. A paper...
Use R programming language to answer and please so show the code as well. A paper manufacturer studied the effect of three vat pressures on the strength of one of its products. Three batches of cellulose were selected at random from the inventory. The company made two production runs for each pressure setting from each batch. As a result, each batch produced a total of six production runs. The data follow. Perform the appropriate analysis. Table is below Batch Pressure...
Please answer everything in R programming language. Show the code to me as well. Thank You...
Please answer everything in R programming language. Show the code to me as well. Thank You 1. Problem Open dataset stat500. Package: faraway. Use R (a) Calculate the correlation matrix. 10. (b) Plot total vs hw, to see how strong the relationship. (c) Build a simple linear regression: total regressed against midterm. Print model output. (d) Calculate directly the coefficients as in (3) (e) Calculate the Residual standard error s, as in (4). (f) Calculate the standard error of beta_1,...
The data below represents the bacterial growth in a liquid culture over a number of days....
The data below represents the bacterial growth in a liquid culture over a number of days. Day 0 4 8 12 16 20 Amount ×106 67 84 98 125 149 185 Find a best-fit equation to the above data trend using polynomial regression with parabolic model given as: ? = ?? + ?1? + ?2?2 After calculating the values of ao, a1, and a2, substitute these values in the above parabolic model. Plot the given data and the obtained parabolic...
Code in C++ programming language description about read and write data to memory example.
Code in C++ programming language description about read and write data to memory example.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT