The grouping variable's column in data must be a factor

Dear All,

I am using rstudio.cloud project for analysis of dissolution data. how to fix error occurred in following code, please refer reprex() output for reference.

type=c('R','R','R','R','R','R','R','R','R','R','R','R','T','T','T','T','T','T','T','T','T','T','T','T')
as.factor(type)
#>  [1] R R R R R R R R R R R R T T T T T T T T T T T T
#> Levels: R T
disso2=data.frame(type,tablet=c(1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12),
t.5=c(2.4,4.3,4.3,4.6,4.5,4.3,6,3.9,4.6,4.3,4.1,4.3,1.4,4.2,3.9,4.1,4.3,4.2,2.1,4,4.1,4.2,4.3,4.5),
t.10=c(5,5.1,5.1,4.9,5,4.8,4.8,4.9,4.9,5,4.8,   4.9,4.7,5,4.9,5.2,5.4,4.9,4.8,5,5.2,5.2,5.3,5.4),
t.15=c(5,5.5,5.4,5.1,5.3,5.2,5.3,5.3,5.3,5.1,5.2,5.3,5.6,5.3,5.8,5.5,5.8,5.6,5.4,5.9,5.7,5.7,5.7,5.7),
t.20=c(5.4,5.6,5.6,5.3,5.6,5.5,3.5,5.3,5.6,5.7,5.7,5.9,5.7,5.9,6,5.9,6.1,5.8,5.7,5.9,6.1,6.2,6,6.1),
t.30=c(3.1,5.8,6,   6,6,6,5.8,6,6,5.9,5.9,5.8,5.9,6.4,6.5,6.4,6.4,6.2,6.3,6.4,6.4,6.6,6.4,6.3),
t.45=c(6,6.3,6.2,6.1,5.9,6.1,6.1,6.3,6,6.2,5.9,5.9,6.5,6.4,6.4,6.4,6.5,6.5,6.2, 6.2,6.6,6.5,6.5,6.7),
t.60=c(6.1,6.5,6.3,6.5,6.4,6.1,6,6.5,6.3,6.4,6.2,6.4,6.6,6.8,6.8,7.1,6.9,6.9,6.7,6.8,6.9,6.9,6.9,7.2))
print(disso2)
#>    type tablet t.5 t.10 t.15 t.20 t.30 t.45 t.60
#> 1     R      1 2.4  5.0  5.0  5.4  3.1  6.0  6.1
#> 2     R      2 4.3  5.1  5.5  5.6  5.8  6.3  6.5
#> 3     R      3 4.3  5.1  5.4  5.6  6.0  6.2  6.3
#> 4     R      4 4.6  4.9  5.1  5.3  6.0  6.1  6.5
#> 5     R      5 4.5  5.0  5.3  5.6  6.0  5.9  6.4
#> 6     R      6 4.3  4.8  5.2  5.5  6.0  6.1  6.1
#> 7     R      7 6.0  4.8  5.3  3.5  5.8  6.1  6.0
#> 8     R      8 3.9  4.9  5.3  5.3  6.0  6.3  6.5
#> 9     R      9 4.6  4.9  5.3  5.6  6.0  6.0  6.3
#> 10    R     10 4.3  5.0  5.1  5.7  5.9  6.2  6.4
#> 11    R     11 4.1  4.8  5.2  5.7  5.9  5.9  6.2
#> 12    R     12 4.3  4.9  5.3  5.9  5.8  5.9  6.4
#> 13    T      1 1.4  4.7  5.6  5.7  5.9  6.5  6.6
#> 14    T      2 4.2  5.0  5.3  5.9  6.4  6.4  6.8
#> 15    T      3 3.9  4.9  5.8  6.0  6.5  6.4  6.8
#> 16    T      4 4.1  5.2  5.5  5.9  6.4  6.4  7.1
#> 17    T      5 4.3  5.4  5.8  6.1  6.4  6.5  6.9
#> 18    T      6 4.2  4.9  5.6  5.8  6.2  6.5  6.9
#> 19    T      7 2.1  4.8  5.4  5.7  6.3  6.2  6.7
#> 20    T      8 4.0  5.0  5.9  5.9  6.4  6.2  6.8
#> 21    T      9 4.1  5.2  5.7  6.1  6.4  6.6  6.9
#> 22    T     10 4.2  5.2  5.7  6.2  6.6  6.5  6.9
#> 23    T     11 4.3  5.3  5.7  6.0  6.4  6.5  6.9
#> 24    T     12 4.5  5.4  5.7  6.1  6.3  6.7  7.2
library(disprofas)
mimcr(data = disso2, tcol = 3:9, grouping = "type")
#> Error in mimcr(data = disso2, tcol = 3:9, grouping = "type"): The grouping variable's column in data must be a factor.

Created on 2022-12-01 with reprex v2.0.2

There are only a relative handful of R functions that will change an object just by being called. One is colnames(x) <- c("a","b","c") In general, however, you need to assign the return value to something.

type <- c('R','R','R','R','R','R','R','R','R','R','R','R','T','T','T','T','T','T','T','T','T','T','T','T')
as.factor(type)
#>  [1] R R R R R R R R R R R R T T T T T T T T T T T T
#> Levels: R T
is.factor(type)
#> [1] FALSE
type <- as.factor(type)
is.factor(type)
#> [1] TRUE
2 Likes

thanks now its working fine

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.