Iterate over multiple columns in a csv file and convert them into a list of lists in R

时间:2017-06-15 09:44:56

标签: r list csv multiple-columns

Suppose I have a csv file which have 2 columns username, tweet. For each user, how can get all the tweets he made into a list. For example the list should be something like list(c(user1,tweet1,t2,t3),c(u2,t7,t8,t9),....)

usernameslist <- alldata$V5
usernameslist <- usernameslist[-1]
tweetslist <- alldata$V2
tweetslist <- tweetslist[-1]

user_and_his_tweets <- split(tweetslist,usernameslist, drop = FALSE )
mylist <- list() 
for(i in 1:length(user_and_his_tweets)){
mylist <- list(mylist,c(names(user_and_his_tweets[i]),as.character(user_and_his_tweets[[i]])))
}

This is what I tried. But "mylist" is not in the format I wanted.

0 个答案:

没有答案
相关问题