create empty data.frama

i want to create an ampty data.frame that i will then fill with a rbind in a "for" loop

tirage <- function(N){#on tire N echantillons de tirages de n cartes
  #on retourne le data.frame de N lignes et n colonnes
  laliste <- laliste[-1,]
  for (i in 1:N){
    laliste <- rbind(laliste,sample(carte, size =n, replace=F))

the little problem is : i find my instruction

  laliste <- laliste[-1,]

a bit weird
is there not a more natural way to create an empty data.frame ?

I would not create a data frame in preference to a vector.

tirage <- function(x) {
  carte <- 1:100
data.frame(résultat = sapply(1:10,tirage))
#>    résultat
#> 1        45
#> 2         4
#> 3        16
#> 4        79
#> 5        24
#> 6        30
#> 7        34
#> 8        88
#> 9        43
#> 10       70

Created on 2023-01-26 with reprex v2.0.2

(my_empty <- data.frame(col1name=logical(0),

hello thanks
but i doesnt work for me since i want to simulate the picking of two or tree cards (so replace=F) so i have to generate line by line

but in fact in the while i have found an other solution with something like


which i find very very much quick comparing to the solution with data.frame

hello and thanks !
could you explain me a little… :slight_smile:

this is how you make data.frames with no rows; you name the columns and you say what type of content they would contain.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.