mikeblazanin / gcplyr

gcplyr is an R package that facilitates wrangling and analysis of microbial growth curve data
https://mikeblazanin.github.io/gcplyr/
Other
29 stars 2 forks source link

make_design: Could expand.grid be useful? #142

Open discoleo opened 1 year ago

discoleo commented 1 year ago

Function: make_design

Many of the functions in this package, including make_design contain a lot of duplicate code. Such code could be moved to specific helper-functions. But independent of this: there might be simpler ways to accomplish some of the tasks.

Cell Identifiers

The cell identifiers can be generated very easy using the expand.grid function and the seq.character described in a previous issue.

# can be generated using the function seq.character described in a previous Issue; idRow = c("A", "B", "C", "D"); nCols = 6; # m = matrix-format m = matrix(apply(expand.grid(idRow, seq(nCols)), 1, paste0, collapse=""), ncol= nCols); print(m) # as vector as.vector(m); as.vector(t(m)); # the transposed values

The last step would include cbind(as.vector(m), _thelabels).

It should be evaluated if this simpler code can be useful.

discoleo commented 1 year ago

Simpler version of code using expand.grid:

idRow = c("A", "B", "C", "D"); nCols = 6; grid = expand.grid(seq(nCols), idRow); # Result: directly as vector; v = paste(grid[,2], grid[,1], sep="");