Reputation: 11
I tried to run anova for my data, but am stuck on this error. I'm a newbie in R. Please anyone can help me? Thank you in advance.
library(data.table)
library(ggplot2)
read_risk_data <- fread("Risk_v2.csv", select = c(1:7))
read_risk_data
read_risk_data[-c(1), ]
risk <- read_risk_data[-c(1), ]
risk
risk.1 <- risk[1:64, ]
risk.1
str(risk.1)
nrow(risk.1)
ncol(risk.1)
class(risk.1)
risk_vp <- c(rep('No.mitigation', 64), rep('Refrigeration', 64), rep('Depuration', 64), rep('Freezing', 64), rep('Thermal.treatment', 64), rep('Thermal.shock', 64), rep('Irradiation', 64))
risk_vp_level <- c(risk.1$No.mitigation, risk.1$Refrigeration, risk.1$Depuration, risk.1$Freezing, risk.1$Thermal.treatment, risk.1$Thermal.shock, risk.1$Irradiation)
risk_vp.1 <- t(risk_vp)
risk_vp.2 <- t(risk_vp.1)
risk_vp_level.1 <- t(risk_vp_level)
risk_vp_level.2 <- t(risk_vp_level.1)
df <- data.frame(risk_vp.2, risk_vp_level.2)
Here is the structure
Classes ‘data.table’ and 'data.frame': 64 obs. of 7 variables:
$ No mitigation : num 2.18e-05 4.47e-05 9.43e-05 6.16e-05 2.60e-05 5.29e-
05 1.10e-04 7.25e-05 2.80e-05 5.67e-05 ...
$ Refrigeration : num 7.80e-06 1.10e-05 1.64e-05 1.30e-05 8.52e-06 1.20e-
05 1.79e-05 1.42e-05 8.83e-06 1.24e-05 ...
$ Depuration : num 7.11e-06 1.58e-05 3.67e-05 2.25e-05 8.57e-06 1.91e-
05 4.41e-05 2.72e-05 9.28e-06 2.07e-05 ...
$ Freezing : num 8.11e-06 1.79e-05 4.16e-05 2.55e-05 9.77e-06 2.17e-
05 5.00e-05 3.08e-05 1.06e-05 2.35e-05 ...
$ Thermal treatment: num 3.44e-09 7.64e-09 2.00e-08 1.11e-08 4.11e-09 9.42e-
09 2.55e-08 1.40e-08 4.42e-09 1.03e-08 ...
$ Thermal shock : num 9.09e-10 2.00e-09 5.07e-09 2.89e-09 1.09e-09 2.46e-
09 6.40e-09 3.60e-09 1.17e-09 2.67e-09 ...
$ Irradiation : num 3.60e-10 8.25e-10 2.21e-09 1.22e-09 4.32e-10 1.03e-
09 2.82e-09 1.54e-09 4.67e-10 1.13e-09 ...
- attr(*, ".internal.selfref")=<externalptr>
And, when I run this code:
df <- data.frame(risk_vp.2, risk_vp_level.2)
It gave me:
Error in data.frame(risk_vp.2, risk_vp_level.2) :
arguments imply differing number of rows: 448, 256
Upvotes: 1
Views: 31226
Reputation: 5958
This simply means that risk_vp.2
and risk_vp_level.2
have different numbers of rows. Try to run nrow(risk_vp.2)
and nrow(risk_vp_level.2)
or dim(risk_vp_level.2)
after each operation to understand where the error is. Also note that
c(rep('No.mitigation', 64), rep('Refrigeration', 64), rep('Depuration', 64), rep('Freezing', 64), rep('Thermal.treatment', 64), rep('Thermal.shock', 64), rep('Irradiation', 64))
Will create one vector of 7*64 elements - if you wanted to create a data.frame
of 7 columns and 64 rows instead you should use cbind
instead of c()
.
Finally, it is hard for us to help you if you don't give us some data that we can use on our side. Please provide minimal reproducible examples in the future - that do not depend on any external file.
Upvotes: 2