Search code examples
rdataframevariablestibble

I want to draw one element out from a tibble variable in R


I have a dataframe that consist of multiple variables, and some of them are tibbles. i have variables like:

[ID, name, symbol, category, urls,....,slug]

In this case slug is a tibble and consist of multiple urls of interst such as [Website, facebooksite, twitter,..,reddit]

I would like to draw out only webpage for each asset as a new variable.

So far I figured out I can get the webpage for

ID=1 data$urls[[1]][1,] and for ID=2 crypto.info1$urls[[2]][1,]

output is
A tibble: 1 x 2
  name    url                 
  <chr>   <chr>               
1 website https://bitcoin.org/

but I want for every ID in a new variable. I hope someone can assist me.

Data example:
| ID |  Name   |Category |   Urls    |
| -- | --------|---------|-----------|
| 1  | Bitcoin |Coin     |2 variables|
| 2  | Litecoin|Coin     |3 variables|
| .  | ........|......   |...........|

when urls is opened it looks like: Data example:

|  Name   |              url           |
| --------|----------------------------|
| Website |https://bitcoin.org/        |
| Reddit  |https://reddit.com/r/bitcoin|
| ........|......                      |

Solution

  • urls <- c()
    
    for(i in 1:length(data$urls)){
    
    urls[i] <- data$urls[[i]][1,2] 
    }
    data$Website <- urls
    

    Thanks to Bensstats send me in the right direction