I am using the Corpus function to read a file I have created in the below mentioned directory.
chk <- Corpus(DirSource("C:\\Users\\TCS Profile\\Documents\\R\\Machine Learning Text\\Naive Bayes"))
Once the corpus is created, when i validate the variable chk created, i find that the content has been read:
str(chk)
List of 1
$ Test.txt:List of 2
..$ content: chr [1:7] "Hi Wassup" "How are You" "Hope it Works!!!" "" ...
..$ meta :List of 7
.. ..$ author : chr(0)
.. ..$ datetimestamp: POSIXlt[1:1], format: "2015-10-14 16:15:17"
.. ..$ description : chr(0)
.. ..$ heading : chr(0)
.. ..$ id : chr "Test.txt"
.. ..$ language : chr "en"
.. ..$ origin : chr(0)
.. ..- attr(*, "class")= chr "TextDocumentMeta"
..- attr(*, "class")= chr [1:2] "PlainTextDocument" "TextDocument"
- attr(*, "class")= chr [1:2] "VCorpus" "Corpus"
The problem is I am unable to access a specific value within the content, let's say the 3rd element. (Hope it Works!!) I have tried using the following code:
chk[[1]][1,3]
Error in chk[[1]][1, 3] : incorrect number of dimensions
Can anyone please tell me how can I access the corresponding element and why such an error is coming for the above type of access?
chk$Test.txt$content[3]
is the clearest way. Modifying your way:chk[[1]][[1]][3]
. Run it in parts so you can figure out how to do it next time, e.g.,chk$Test.txt
andchk$Test.txt$content
– Frank