According to ?meta
meta(crude, type="local", tag="someID") <- someID
will assign the meta data tag someID at the individual document level. What you want is to create a tagging at the collection level. For this, you want to manipulate the DMetaData
attribute of the corpus crude. You can do this as:
meta(crude, type="indexed", tag="someID") <- someID
but I find it much easier to use the access
DMetaData(crude)$someID <- someID
(this at least works for corpora of type VCorpus). With this adjustment:
library("tm")
someID <- paste(letters[1:15], 16:30, sep="")
someTag <- sample(c("a","x","g","h","e"), 15, replace=TRUE)
data(crude) # a corpus with 20 docs
# Need to be sure to allocate full tag and id set.
DMetaData(crude)$someID <- c(someID,rep(NA,5))
DMetaData(crude)$someTag <- rep(NA,20)
mydf <- data.frame(cbind(someTag, someID), stringsAsFactors=FALSE) # Creating a dataframe with similar IDs
mydf <- mydf[sample(nrow(mydf)),] # permutation of elements (rows)
rownames(mydf) <- 1:15 # overwriting the rownames
for (i in 1:nrow(mydf)){
DMetaData(crude)$someTag[DMetaData(crude)$someID==mydf$someID[i]]<- mydf$someTag[i]
}
Result:
> DMetaData(crude)
MetaID someID someTag
1 0 a16 a
2 0 b17 h
3 0 c18 g
4 0 d19 a
5 0 e20 e
6 0 f21 a
7 0 g22 x
8 0 h23 g
9 0 i24 h
10 0 j25 e
11 0 k26 x
12 0 l27 a
13 0 m28 a
14 0 n29 h
15 0 o30 a
16 0 <NA> <NA>
17 0 <NA> <NA>
18 0 <NA> <NA>
19 0 <NA> <NA>
20 0 <NA> <NA>