import data for (i in data) rewrite

Hi to everyone!
I'm just trying to create a dataset taking data from 2 urls, but i'm encountering an error.

Immagine 2020-11-12 192159

When I create the variable, it will be rewritten by the next one observation(url), i wanna know if there is any method to get it not rewritten or(and it will be perfect) if i can add the first 100 object (the object selected contains 100 value each url) from the first url, to the second url, so i can get a variable of 200 value.


Welcome to the RStudio community!

Using a print screen image is not the best way to post a question on here, because we would have to read and type everything by hand if we like to work with your code. Please read the guide on how to create a reprex to make sure folk can start helping your more quickly in future. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

The reason you overwrite now is because in your loop you are writing every time to a thus overwriting the previous values. You can use an apply statement to save everything into a list like so

# c is your vector of urls
myData = lapply(c, function(url){
 page = read_html(url)
 a = html_nodes(page, ".number")

Hope this helps,

Thank you so much, this worked perfectly!
And sorry for the incovenience, next time i will post a code and not a screen!

1 Like

This topic was automatically closed 7 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.