I want to make a data.frame with two columns. The first with the Id of tweets, and the second column the information depends on whether the tweet is a reply or retweet
id_str | x$retweeted_status$id_str or x$in_reply_to_status_id_str
I can make a dataframe with three columns bue I need two.
My code:
ids <- sapply(tweets.list, function(x) x$id_str)
ret_ids <- sapply(tweets.list, function(x) if(is.null(x$retweeted_status)) NA else x$retweeted_status$id_str)
rep_ids <- sapply(tweets.list, function(x) if(is.null(x$in_reply_to_status_id_str)) NA else x$in_reply_to_status_id_str)
isnt.null <- function(x)!is.null(x)
r_ids <- sapply(tweets.list, function(x) if(is.null(x$retweeted_status)) x$in_reply_to_status_id_str else x$retweeted_status$id_str)
data.frame(ids,r_ids)
The output:
Error in data.frame("733222936912351232", NULL, "733220677721968641", :
arguments imply differing number of rows: 1, 0
Data:
ids|ret_ids|rep_ids
1|40|NA
2|32|NA
3|NA|555
4|NA|444
Result desired:
ids|r
1|40
2|32
3|555
4|444