Problem data.frame

Hello everybody,

I want to add two data.frame.
One is empty and the second has 20 rows only where there are only characters.
However i want to do this one several times, with while loop.

Like this :

one <- data.frame()

#initialization of the loop
i <- 1

while (i != 10){
   final <- cbind(one, two)

And the console answer me :

Error in data.frame(..., check.names = FALSE) : 
  the arguments involve different numbers of lines: 0, 20

How can i resolve it ? Because when try, simplier,
final <- cbind(one, two) ten times, it's okay...

Points that strike to me immediately:

  1. Your while loop doesn't make any sense to me. First of all, you're not updating i, so this loop will run forever. Second, even if you add a stopping condition (say i <- (i + 1) before closing the while loop), what will you get? final will still be cbind(one, two), and repeating it has no meaning. Perhaps, you were planning to update final in each repetition, or something like that?

  2. How did you run cbind(one, two), where one is an empty data frame, and two has 20 rows? I failed to run it, as you can find below:

one <- data.frame()
two <- data.frame(1:20)
cbind(one, two)
#> Error in data.frame(..., check.names = FALSE): arguments imply differing number of rows: 0, 20

Please try to ask a properly formulated question with a minimal reproducible example. This will help others to help you. You can go through these helpful posts:

1 Like

For the first point, yes i forgot the i <- i + 1 in my first message..

My real code is this one :

list_carac_by_stuffs <- function(site, list_prod) {
  i <- nrow(list_prod)
  k <- 1
  tmp <- data.frame()
  while(k != i){
    page <- read_html(paste0(site, list_prod[1,k]))

    descrip <- page %>% 
      html_nodes("body") %>%
      html_nodes("#wrapper") %>%
      html_nodes("main") %>%
      html_nodes(".sticky-container") %>%
      html_nodes(".product-section") %>%
      html_nodes(".product-text-description") %>%
      html_nodes("ul") %>%
      html_nodes("li") %>%
    tmp <- cbind(tmp, descrip)

    k <- k + 1

The final goal is to make function which scraping and make data.frame with the caracterictics of stuffs (it's just to improve my skills).

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