Data loss in do.call usage mode

I am trying to combine multiple data frames using rbind. If I call rbind directy, no problem:

> test <- rbind(x)
> is.data.frame(x)
[1] TRUE

however, if I use do.call, I run into a problem when my character columns are reset and the dataframe is converted to a matrix.

>test <- do.call("rbind", x)
> is.data.frame(test)
[1] FALSE

According to the documentation? I tried rbind add stringsAsFactors = FALSE, but no change in behavior. My data tables look something like this:

ID  sequence    descriptor
1   aaacccttt   g12
2   actttgtgt   e34
3   tttgggctc   b12
4   ccgcgcgcg   c12
โ€ฆ   โ€ฆ       ...

and the rbind output looks like this, but the output do.call("rbind", x)looks like this, where the sequence column is no longer a character:

ID  363 426 91
Sequence 98 353 100
descriptor  g12 b12 c12 

do.call, , script . , .

stringsAsFactors = FALSE
dfs <- as.list(ls(pattern="Data_"))
for (i in 1:length(dfs)) {
  x <- get(as.character(dfs[i]))
  AllData <- do.call("rbind", x) 
  }

dfs - , get

.

+5
3

, .

  • stringsAsFactors

, stringsAsFactors, .

. options, :

options(stringsAsFactors=FALSE)

, data.table s:

a <- read.table(textConnection("ID  sequence    descriptor
1   aaacccttt   g12
2   actttgtgt   e34
3   tttgggctc   b12
4   ccgcgcgcg   c12"),
header=T, stringsAsFactors=FALSE)
  • args= do.call()

, do.call() . , @Sacha, dfs data.frame s, data.frame ( ).

# Create list of two data.frames
b <- a
dfs <- list(a, b)

# Or, if you start with a list of their names
dfs <- list("a", "b")
dfs <- lapply(dfs, get)

# Check that this works
do.call("rbind", dfs)
#   ID  sequence descriptor
# 1  1 aaacccttt        g12
# 2  2 actttgtgt        e34
# 3  3 tttgggctc        b12
# 4  4 ccgcgcgcg        c12
# 5  1 aaacccttt        g12
# 6  2 actttgtgt        e34
# 7  3 tttgggctc        b12
# 8  4 ccgcgcgcg        c12

, data.frame, (-1) list, : dfs <- list(a)

+4

. , :

Data:
    x <- read.table(textConnection("ID  sequence    descriptor
    1   aaacccttt   g12
    2   actttgtgt   e34
    3   tttgggctc   b12
    4   ccgcgcgcg   c12"),
    header=T, stringsAsFactors=FALSE)

:

rbind(x)

, . , , . :

do.call("rbind", x)

, , rbind() x. . , , :

rbind(x$ID,x$sequence,x$descriptor)

. , , , data.frames , .

, x - , . .

+2

, , , , Reduce. , .

dfs <- as.list(ls(pattern="Data_"))
Reduce('rbind', dfs)
+1

All Articles