I'm working on a Twitter analysis. I'm trying to automate the extraction of timeline of the followers of a certain twitter account.
This is my code
library(tidyverse)
library(rtweet)
set.seed(1234)
filas <- nrow(twitter)
muestra <- sample(filas*0.30)
twitter_sample <- twitter[muestra,]
twitter_sample$Nick.del.Cliente <- as.character(twitter_sample$Nick.del.Cliente)
i <- 1
for (i in 1:length(muestra)){
usuario <- paste('@', twitter_sample$Nick.del.Cliente, sep = '' )
}
(usuario)
j <- 1
texto <- data.frame(matrix(ncol = 283, nrow = 100))
tipo <- data.frame(matrix(ncol = 283, nrow = 100))
cantidad <- data.frame(matrix(ncol = 283, nrow = 100))
for (j in 1:283){
total <- get_timeline(usuario[j], n =100, include_rts = F)
texto[,j] <- total$text
tipo[,j] <- total$source
cantidad[,j] <- total$display_text_width
}
I choose a representative sample of the followers, then I added a "@" to every single ID user and create a list with the ID called "usuario" (usuario means user in Spanish).
Then I created 3 empty data frames, when colums are equal to users that I have and rows are equal to the numbers of tweets that I need.
In 'for' I need the next things:
- Access to the first user's timeline
- Take 'text' column and add it in to first column of 'texto' dataframe
- Take 'source' column and add it in to first column of 'tipo' dataframe
- Take 'display_text_width; and add it in to first column of 'cantidad' dataframe
Then repeat the same with the second user and add the same information in the second column to the dataframes, and then de third users, etc...
When I run the second 'for' I get this error.
Error in `[<-.data.frame`(`*tmp*`, , j, value = c("@Bellealouette Influencia? Quien es ella que no sabe que es influenza?", :
replacement has 96 rows, data has 100.
If i change the dataframe size the error is the same, but with other numbers
Error in `[<-.data.frame`(`*tmp*`, , j, value = c("@Bellealouette Influencia? Quien es ella que no sabe que es influenza?", :
replacement has 78 rows, data has 80