How can I create a table of only the unique elements in a list so I can order the elements in terms of frequency?

Ger

I have tried running the code below, however it does not work as the arguments are not all of equal length.

sentence= "I like tea and I love coffee and biscuits"
    words = function(x) {
      txt = unlist(strsplit(x,' '))
      wl = list()
      for(i in seq_along(txt)) {
        wrd = txt[i]
        wl[[wrd]] = c(wl[[wrd]], i)
      }
      class(wl) <- "wordclass"
      return(wl)
    }
    summary.wordclass <- function(y) {
      cat("the frequency of words",names(sort(table(y), decreasing=TRUE)),"\n")
    }
    wordfreq=words(sentence)
    summary(wordfreq)

I want to get an output like

[1] "I"     "and"   "like"    "tea"   "love"   "coffee" 

However, I am getting the error

Error in table(y) : all arguments must have the same length

If anyone could help that would be great!

Cath

would

names(sort(table(unlist(strsplit(sentence," "))),decreasing=T))

work for you ?

the output is

[1] "and" "I" "biscuits" "coffee" "like" "love" "tea"

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I create connected/dependent select elements in Formik?

분류에서Dev

How can i get the common elements in the first two list and save to a new list in python 3?

분류에서Dev

Using a Javascript switch statement, how can I count the number of elements (numbers only) in an array?

분류에서Dev

How can I create List of rectangles in TypeScript?

분류에서Dev

How can I create a resource list on Apigility?

분류에서Dev

How i can iterate list to get 10 elements each time in java

분류에서Dev

How can I make elements visible in C# Webbrowser?

분류에서Dev

how can i use split() with a big number of elements, java

분류에서Dev

How do I create/ sort a Table containing a list of matched terms with their corresponding counts

분류에서Dev

Why can't I draw elements to the stage?

분류에서Dev

How can I create a table widget using Qt

분류에서Dev

Android - How can i create a "black list" for the files of my application

분류에서Dev

How can I merge two complex JSON objects with only unique or different values only showing in resultant array

분류에서Dev

How can I save the order of the tree?

분류에서Dev

How can I create an alias so that when I enter "kt" it executes "killall gnome-terminal"?

분류에서Dev

How can I compare elements in 2 lists in the same index in their respective lists in Python?

분류에서Dev

Using jQuery, how can I select elements by multiple data-attributes?

분류에서Dev

How can I make all elements of a view be entered proportionally to the screen(xCode 6, using swift)?

분류에서Dev

How can I split a string on separators, and keep the separators as elements in the resulting array?

분류에서Dev

How can I access elements of a JSON return from a Stripe api call?

분류에서Dev

How can I know which fiels cause IntegrityError when inserting into a table with multiple unique fields?

분류에서Dev

How can I suppress output from grep, so that it only returns the exit status?

분류에서Dev

How can I create launcher icon for PhpStorm?

분류에서Dev

How can I create multiple SSH keys?

분류에서Dev

How can I create A Class with Trait On Scala?

분류에서Dev

How Can I Create A Custom Property Type

분류에서Dev

How Can I Create A Custom Property Type

분류에서Dev

How can I create dynamic CONTAO pages?

분류에서Dev

How can I get SSRS to create subheadings?

Related 관련 기사

  1. 1

    How can I create connected/dependent select elements in Formik?

  2. 2

    How can i get the common elements in the first two list and save to a new list in python 3?

  3. 3

    Using a Javascript switch statement, how can I count the number of elements (numbers only) in an array?

  4. 4

    How can I create List of rectangles in TypeScript?

  5. 5

    How can I create a resource list on Apigility?

  6. 6

    How i can iterate list to get 10 elements each time in java

  7. 7

    How can I make elements visible in C# Webbrowser?

  8. 8

    how can i use split() with a big number of elements, java

  9. 9

    How do I create/ sort a Table containing a list of matched terms with their corresponding counts

  10. 10

    Why can't I draw elements to the stage?

  11. 11

    How can I create a table widget using Qt

  12. 12

    Android - How can i create a "black list" for the files of my application

  13. 13

    How can I merge two complex JSON objects with only unique or different values only showing in resultant array

  14. 14

    How can I save the order of the tree?

  15. 15

    How can I create an alias so that when I enter "kt" it executes "killall gnome-terminal"?

  16. 16

    How can I compare elements in 2 lists in the same index in their respective lists in Python?

  17. 17

    Using jQuery, how can I select elements by multiple data-attributes?

  18. 18

    How can I make all elements of a view be entered proportionally to the screen(xCode 6, using swift)?

  19. 19

    How can I split a string on separators, and keep the separators as elements in the resulting array?

  20. 20

    How can I access elements of a JSON return from a Stripe api call?

  21. 21

    How can I know which fiels cause IntegrityError when inserting into a table with multiple unique fields?

  22. 22

    How can I suppress output from grep, so that it only returns the exit status?

  23. 23

    How can I create launcher icon for PhpStorm?

  24. 24

    How can I create multiple SSH keys?

  25. 25

    How can I create A Class with Trait On Scala?

  26. 26

    How Can I Create A Custom Property Type

  27. 27

    How Can I Create A Custom Property Type

  28. 28

    How can I create dynamic CONTAO pages?

  29. 29

    How can I get SSRS to create subheadings?

뜨겁다태그

보관