HOW to count the word as there is a column about sentencehi,
I have a question about how to count the word in a column about sentences.
for example, if a participant writes "I like chocolate bars" , it would be counted as 4 words. if the sample size is 100, how can I count words in this column by each participant?
best wishes,
Rongyu
AnalyticsData TableDOEScriptingRe: HOW to count the word as there is a column about sentenceIt is a simple task. Just count the number of elements that are created using the Words() function.
Names Default To Here( 1 );
string = "I like chocolate bars";
Show( Length( Words( string ) ) );
Re: HOW to count the word as there is a column about sentenceBuilding on what txnelson mentioned, if you have a column with strings, column: Strings, then consider something like this
- Create new column: Num of Words
- Set formula to
Length( Words( :Strings ) )
This will fill in the Num of Words column with the number of words found in the Strings column. The data type will initially be character, but you can modify the data type and modeling to your needs.
Re: HOW to count the word as there is a column about sentencemany thanks indeed!!
may I ask another question, if I need to count the number of sentences in a string, what should I do?
thanks again.
Re: HOW to count the word as there is a column about sentenceAll of the JMP functions are defined in the Scripting Index. The description of the Words() function shows that it allows for a second element which defines what delimiter(s) are to be used in the specification of what is a "Word".

The default delimiter is a blank. If you change the delimiter element to specify both a period and a question mark, I believe what you will get is a separate entry in the output list, for each sentence.
Re: HOW to count the word as there is a column about sentenceTo parse out sentences you could use punctuation marks as delimiters to the words function.
sentences = "The quick brown fox jumped over the lazy dog. Hello World! Where's Waldo?";
slist = words(sentences, ".!?");
print(slist);
nsentences = nitems(slist);
print(nsentences);
Output from the log window:
{"The quick brown fox jumped over the lazy dog", " Hello World", " Where's Waldo"}
3Re: HOW to count the word as there is a column about sentenceOther option could be to replace punctuation marks with "" and then check for string lengths
Names Default To Here(1);
sentences = "The quick brown fox jumped over the lazy dog. Hello World! Where's Waldo?";
sentences_new = Substitute(sentences, {".", "!", "?"}, ""); // or regex with GLOBALREPLACE
show(sentences_new);
nsentences = Length(sentences) - Length(sentences_new);
show(nsentences);