+ Reply to Thread
Results 1 to 8 of 8

frequency of an element or a number in a line

  1. #1
    Registered User
    Join Date
    05-15-2008
    Posts
    6

    frequency of an element or a number in a line

    I need to calculate the frequency of an element/number per line
    The attached table explains it all!
    Attached Images Attached Images

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    What are the expected results?

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482
    Quote Originally Posted by seether
    I need to calculate the frequency of an element/number per line
    The attached table explains it all!
    Your picture asks for the number of "a"'s/the number of a's+b's
    =COUNTIF(A1:J1,"*a*")/(COUNTIF(A1:J1,"*a*")+COUNTIF(A1:J1,"*b*"))

  4. #4
    Registered User
    Join Date
    05-15-2008
    Posts
    6
    Thanks Dave but it is giving me an error!
    Look at the attached graphic
    Attached Images Attached Images

  5. #5
    Registered User
    Join Date
    05-15-2008
    Posts
    6
    Quote Originally Posted by daddylonglegs
    What are the expected results?
    the expected results are frequencies:
    if a line contains:
    aa ab bb aa
    then there are 5 "a" and 3 "b" the result would be: 3/5+3

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by seether
    Thanks Dave but it is giving me an error!
    Look at the attached graphic
    Are you perhaps on a European version of Excel...where ; is used as argument separators instead of ,

    Please Login or Register  to view this content.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  7. #7
    Registered User
    Join Date
    05-15-2008
    Posts
    6
    Quote Originally Posted by NBVC
    Are you perhaps on a European version of Excel...where ; is used as argument separators instead of ,

    Please Login or Register  to view this content.
    Yep excellent! That solved it Thanks a lot NBVC :thumbs up:

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by seether
    That solved it
    Are you sure?

    COUNTIF won't count the number of "a"s and "b"s in a cell, it'll only count how many cells have "a" s or "b"s, e.g. for your above example

    Quote Originally Posted by seether
    if a line contains:
    aa ab bb aa
    then there are 5 "a" and 3 "b" the result would be: 3/5+3
    then you presumably want a result of 3/(3+5)=0.375?

    COUNTIF formula will give =2/(3+2)=0.4

    To get 3.75, assuming cells only contain "a"s and "b"s as per your example

    =SUMPRODUCT(LEN(A1:J1)-LEN(SUBSTITUTE(A1:J1;"b";"")))/SUMPRODUCT(LEN(A1:J1))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1