Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:04:18+00:00 2026-06-18T14:04:18+00:00

I am trying to do some very basic text analysis with the tm package

  • 0

I am trying to do some very basic text analysis with the tm package and get some tf-idf scores; I’m running OS X (though I’ve tried this on Debian Squeeze with the same result); I’ve got a directory (which is my working directory) with a couple text files in it (the first containing the first three episodes of Ulysses, the second containing the second three episodes, if you must know).

R Version: 2.15.1
SessionInfo() Reports this about tm: [1] tm_0.5-8.3

Relevant bit of code:

library('tm')
corpus <- Corpus(DirSource('.'))
dtm <- DocumentTermMatrix(corpus,control=list(weight=weightTfIdf))

str(dtm)
List of 6
 $ i       : int [1:12456] 1 1 1 1 1 1 1 1 1 1 ...
 $ j       : int [1:12456] 2 10 12 17 20 24 29 30 32 34 ...
 $ v       : num [1:12456] 1 1 1 1 1 1 1 1 1 1 ...
 $ nrow    : int 2
 $ ncol    : int 10646
 $ dimnames:List of 2
  ..$ Docs : chr [1:2] "bloom.txt" "telemachiad.txt"
  ..$ Terms: chr [1:10646] "_--c'est" "_--et" "_--for" "_--goodbye," ...
 - attr(*, "class")= chr [1:2] "DocumentTermMatrix" "simple_triplet_matrix"
 - attr(*, "Weighting")= chr [1:2] "term frequency" "tf"

You will note, that the weighting appears to still be the default term frequency (tf) rather than the weighted tf-idf scores that I’d like.

Apologies if I’m missing something obvious, but based on the documentation I’ve read, this should work. The fault, no doubt, lies not in the stars…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:04:19+00:00Added an answer on June 18, 2026 at 2:04 pm

    If you look at the DocumentTermMatrix help page, an at the example, you will see that the control argument is specified this way :

    data(crude)
    dtm <- DocumentTermMatrix(crude,
               control = list(weighting = function(x) weightTfIdf(x, normalize = FALSE),
                              stopwords = TRUE))
    

    So, the weighting is specified with the list element named weighting, not weight. And you can specify this weighting by passing a function name or a custom function, as in the example. But the following works too :

    data(crude)
    dtm <- DocumentTermMatrix(crude, control = list(weighting = weightTfIdf))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to get to the bottom of this! i have a very basic app
I'm trying to do some very basic time math - basically, given inputs of
I have a very basic model - User I am trying to do some
I'm trying to decide how to implement a very basic licensing solution for some
I am trying to correct a text that has some very typical scanning errors
So I'm trying to do some very basic div re-sizing based on the properties
I'm trying to do some very basic arithmetic and am getting hung up. I'm
I'm having trouble trying to achieve some very basic layout behavior with Auto Layout.
I am trying to write a very basic text string to my documents directory
This is probably very basic but I'm trying to test the Google Places API.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.