Helps users to easily convert a two-way table (genotype vs environment) to a
'long' format data. The data in mat
will be gathered into three
columns. The row names will compose the first column. The column names will
compose the second column and the third column will contain the data that
fills the two-way table.
Arguments
- mat
A two-way table. It must be a matrix or a data.frame with rownames.
- gen_in
Where are the genotypes? Defaults to
'rows'
. If genotypes are in columns and environments in rows, set togen_in = 'cols'
.
Author
Tiago Olivoto tiagoolivoto@gmail.com
Examples
# \donttest{
library(metan)
set.seed(1)
mat <- matrix(rnorm(9, 2530, 350), ncol = 3)
colnames(mat) <- paste("E", 1:3, sep = "")
rownames(mat) <- paste("G", 1:3, sep = "")
make_long(mat)
#> # A tibble: 9 × 3
#> ENV GEN Y
#> <chr> <chr> <dbl>
#> 1 E1 G1 2311.
#> 2 E1 G2 2594.
#> 3 E1 G3 2238.
#> 4 E2 G1 3088.
#> 5 E2 G2 2645.
#> 6 E2 G3 2243.
#> 7 E3 G1 2701.
#> 8 E3 G2 2788.
#> 9 E3 G3 2732.
gen_cols <- t(mat)
make_long(gen_cols, gen_in = "cols")
#> # A tibble: 9 × 3
#> ENV GEN Y
#> <chr> <chr> <dbl>
#> 1 E1 G1 2311.
#> 2 E1 G2 2594.
#> 3 E1 G3 2238.
#> 4 E2 G1 3088.
#> 5 E2 G2 2645.
#> 6 E2 G3 2243.
#> 7 E3 G1 2701.
#> 8 E3 G2 2788.
#> 9 E3 G3 2732.
# }