Order in which mapply operates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Order in which mapply operates

Mimic03
I've been a couple of weeks dealing with a problem i haven't been able to resolve. I'm preparing tagged twitter data to be trained with skip gram, for training subject referencing in phrases.

Let me explain a bit better with an example, let's say i have a root (original) tweet:

"the scientist was reading the paper" where i tag every reference with the tag CAD just like html:
"the <CAD=1> scientist</CAD> was reading the <CAD=2>paper</CAD>"
and also every reply to that tweet is tagged the same way, if it refers to the scientist or paper:

reply 1: "yes <CAD=1>stephen hawkins</CAD> likes reading <CAD=2>those</CAD>"

So i have separated all this with lists by the tags CADS for example like this:

> rootcads[[1]]
     [,1]    [,2]    [,3]    [,4]  
[1,] "CAD=1" "CAD=2" "CAD=3" "CAD=4"
which corresponds to 1 root tweet

> replycads[[1]]
     [,1]    [,2]  
[1,] NA      ""    
[2,] "CAD=1" ""    
[3,] "CAD=4" "CAD=3"
which corresponds to 3 replies to that one root tweet

Now my objective is to create a vector or list in which has the CAD tag corresponding to the to words, for example:
V1<-c(CAD=1,scientists,stephen hawkings)
V2<-c(CAD=2,paper,those)

but making the comparison when one list is only a row and the other one is 2 dimensional, where every tweet has different number of replies makes a mess in my brain.

I have made attemps:
nti<-identical(rootcads[[1]][1],replycads[[1]][2,1])
if(nti==TRUE){
  #
  vctr<-c(rootcads[[1]][1],rootwords[[1]][1],replywords[[1]][1])
}

and for looping on lists i tried of course mapply,

mapply(identical,rootcads[[1]][1],replycads[[1]])

where:

 rootcads[[1]]
     [,1]    [,2]    [,3]    [,4]  
[1,] "CAD=1" "CAD=2" "CAD=3" "CAD=4"

> replycads[[1]]
     [,1]    [,2]  
[1,] NA      ""    
[2,] "CAD=1" ""    
[3,] "CAD=4" "CAD=3"

and this mapply returns:

> mapply(identical,rootcads[[1]][1],replycads[[1]])
CAD=1  <NA>  <NA>  <NA>  <NA>  <NA> 
FALSE  TRUE FALSE FALSE FALSE FALSE

so yes its making the comparison but its reading by columns, i need it to be read by rows so it compares one reply at a time, all of this so i can automate the creation of this vector. I've also tried using mapply with for loops but this has only made things much more complex, maybe is my lack of experience but there must be a simpler, easier way to achieve this.

Help please, you're my only hope...
Reply | Threaded
Open this post in threaded view
|

Re: Order in which mapply operates

DylanCarey
This is a very detailed example. I am novice in R, only studying it at university and gaining knowledge in research paper writing, but I aim to use R for my sociological research in a field of digital communications. Hope this explanation will help to build a research strategy.