-2

This code will be used to count number of links in my tweets collection. The collection is collected from 10 accounts. The questions is, how could I loop through the ten accounts in one code and drop the output in a table or graph? "Unames" is representing the name of the account. Thanks in adavance,

mydata <- read.csv("tweets.csv",sep=",", header=TRUE)
head(mydata)
dim(mydata)
colnames(mydata)

****#tweets for each university****

table(mydata$University)
Unames<- unique(mydata$University)
mystring <- function(Uname, string){
     mydata_temp <- subset(mydata,University==Uname)
     mymatch <- rep(NA,dim(mydata_temp)[1])
     for(i in 1:dim(mydata_temp)[1]){
       mymatch[i] <- length(grep(string, mydata_temp[i,2]))
     }

     return(mymatch)
}

**#web link e.g. (Here I would like to see the total links for all universities in table or graph. The below code is only giving me the output one by one!

    mylink <- mystring(Unames[1],"http://")
  • I think you should edit the question to include an example and desired output. It seems clear that you do not yet have any code and that you want some coding done to process an existing body of data but the structure of that data is not described in enough detial to support an answer. – IRTFM Feb 19 '15 at 19:38
  • @BondedDust thank you for your comment. I did some editing, I hope that my question is clear now. Thanks again, – saldaihani Feb 19 '15 at 20:10
  • @BondedDust Thanks a million. It works fine, but how to convert the output to a table or graph with a university name for each row? – saldaihani Feb 20 '15 at 02:36
  • Without a the output of `dput(mylink[[1]])` it's going to be very difficult to guess what sore of structure we need to work with. Remember, we cannot see your file. – IRTFM Feb 20 '15 at 04:45

1 Answers1

0

So my suspicions are wrong and you do have a body of data for which this command produces the desired results (and you expect all the :

 mylink <- mystring(Unames[1],"http://")

In that case, you should just do this:

links_list <- lapply(Unames, mystring, "http://")
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • The output of the following code is the total number of links for a university name (Unames). `mylink <- mystring(Unames[1],"http://")` and the result is `[1] 1964`. When I use `dput(mylink[[1]])` the result is `1L`. – saldaihani Feb 20 '15 at 15:23
  • I wish if you could answer my question. I appreciate your help in this regard. – saldaihani Feb 21 '15 at 01:58