I found the following command to create an empty data frame whose columns have a name and a type:
dataFrameMio = data.frame("col1" = character(0), "col2" = numeric(0), "col3"= numeric(0))
class(dataFrameMio$col1) # character OK
class(dataFrameMio$col2) # numeric OK
class(dataFrameMio$col3) # numeric OK
And I found this code where the type is automatically set to logical. Is it possible to specify the type also in this case?
colonne = c("col4", "col5", "col6")
dataFrameMio2 = data.frame((matrix(nrow = 0, ncol = length(colonne))))
colnames(dataFrameMio2) = colonne
print(dataFrameMio2)
class(dataFrameMio2$col4) # logical
class(dataFrameMio2$col5) # logical
class(dataFrameMio2$col6) # logical
matrixcan have only a single typenrow = 0, and thus it by default changes to logical. checkmatrix(nrow = 0, ncol = length(colonne)) %>% str logi[0 , 1:3]