I have executed the following script:
> results <- list()
> results$gp1 <- c(19, 18.5, 12)
> results$gp1 <- c(19, 17, 15)
> results$gp2 <- c(19, 18.5, 12)
> results$gp3 <- c(20, 19.5, 18)
> results
$`gp1`
[1] 19 17 15
$gp2
[1] 19.0 18.5 12.0
$gp3
[1] 20.0 19.5 18.0
> df_res <- data.frame(results)
> df_res_a <- as.data.frame(results)
> str(df_res)
'data.frame': 3 obs. of 3 variables:
$ gp1: num 19 17 15
$ gp2: num 19 18.5 12
$ gp3: num 20 19.5 18
> str(df_res_a)
'data.frame': 3 obs. of 3 variables:
$ gp1: num 19 17 15
$ gp2: num 19 18.5 12
$ gp3: num 20 19.5 18
It seems like both as.data.frame(x)
and data.frame(x)
work similarly when coercing the list into data frame. So which method should be used? Especially in case of large data volumes?