List of All Functions (Alphabetical) in CODAP

A | B | C | D | E | F | G | H | I | J | L | M | N | P | R | S | T | U | V | W | Y

Function

Description

Example

abs(number) Computes the absolute value of its argument. This is equivalent to using the absolute value bars.

abs(3 – 5) is 2

abs(3-7) = |3 – 7|=4

acos(radians)  Returns the angle in radians that corresponds to the specified arccosine value [–1, 1]. acos(1) returns 0 radians
asin(radians)  Returns the angle in radians that corresponds to the specified arcsine value [–1, 1]. asin(1) returns 1.57, pi/2 radians
atan(radians)  Returns the angle in radians that corresponds to the specified arctangent value [–1, 1]. atan(1) returns 0.79, pi/4 radians
atan2(x, y)  Returns the angle in radians between the x-axis and the specified coordinate point.

atan2(1,1) returns 0.79, pi/4 radians

boolean(expression)  Returns the value of its argument converted to a boolean value.

boolean(age > 60) is true or false

age > 60 is true or false

beginsWith(stringToLookIn, stringToFind) Takes two arguments and returns true if the first begins with the second. beginsWith(LastName, "Mc") will return true for “McBride” and false for “Binker”
caseIndex A value equivalent to the case’s row number in a case table. No parentheses are needed. It only makes sense when used as part of the formula of an attribute. modulo(caseIndex, 3) will return {1, 2, 0, 1, 2} as values for the first five cases in a collection.
ceil(number) Returns the closest integer greater than or equal to its argument. ceil(–10.7) returns –10
charAt(stringToLookIn, index) Returns the character at the specified position.  
combinations(n, k) Returns the number of ways that k things can be drawn from a set of n things without regard to order. The formula is n!/(k!(n-k)!).

combinations(5, 3) returns 10

combinations(20, 7) returns 77520

combine(value) Returns the aggregated concatenation of its evaluated argument values.

combine(flip) might return "HHT" when there are three cases each with value "H" or "T"

combine(1) returns 1, repeated for the number of cases in the case table

correlation(xExpr, yExpr, filter) Computes Pearson's correlation coefficient for two attributes. The result does not depend on order.

correlation(fathers_height, sons_height) computes the correlation coefficient for the two attributes.

correlation(age, height, age<18) computes the correlation of age and height for those cases that have age less than 18.

concat(string1, string2, ... string10)

Takes up to ten arguments and returns a string. The arguments can be numeric or strings. Note: You have to include an argument for the space to get a space in the caption.

if a case has the value “Denise” for the attribute Name and the value “likes dogs” for the attribute Hobby, then concat(Name, " ", Hobby) returns “Denise likes dogs.”

count(value) With no arguments, this returns the number of cases in the collection. An optional argument serves as a filter for the cases that will be counted. count(NumberOfPets > 0) returns the number of cases for which NumberOfPets is greater than zero.
cos(radians) Returns the angle in radians that corresponds to the specified cosine value [–1, 1]. cos(0.5) returns 0.88 radians
date(year, month, day)

Returns a date/time value corresponding to its arguments. If any argument is omitted it is defaulted to 0 (or 1 for the day). If a single large argument is specified, it is assumed to be seconds since January 1, 1970 and is converted accordingly.

date(1777, 4, 7) returns April 7, 1777

date(1395154345) returns 3/18/2014 7:52:25 AM

dayOfMonth(date) Returns the day of the month corresponding to the given date. If date is Aug 31, 2005, dayOfMonth(date) returns 31
dayOfWeek(date) Returns the day of the week (as a number) corresponding to the given date. If date is Aug 31, 2005, dayOfWeek(date) returns 4 because August 31, 2005 is a Wednesday
dayOfWeekName(date) Returns the long name of the day of the week corresponding to the given date.  If date is Aug 31, 2005, dayOfWeekName(date) returns "Wednesday"
endsWith(stringToLookIn, stringToFind) Takes two arguments and returns true if the first ends with the second. endsWith(LastName, "er") returns true for “Binker” and false for “McBride"
exp(number) Returns the result of raising e, the base of natural logs to a power. exp(2) is 7.39, the same as e squared
findString(stringToLookIn, stringToFind, start) Takes three arguments, returning the position of stringToFind in stringToFind starting from start. The first character of stringToLookIn is numbered 1. Returns 0 if stringToFind is not found.
The third argument need not be present and defaults to 1.
findString("mathematics", "the") returns 1, but findString("mathematics", "the", 2) returns 6
first(attribute, filter) Returns the value of its argument evaluated for the first case.

first(population) returns the first value of the attribute population

first(population,sex="female") returns the first value for the attribute population for which the attribute sex is female

floor(number) Returns the closest integer less than or equal to its argument. floor(–10.7) returns –11
frac(number)  Returns the fractional or noninteger part of a number x. frac(1.5) returns 0.5
greatCircleDistance(latitude1, longitude1, latitude2, longitude2) Returns the shortest distance between two points on the surface of the earth. greatCircleDistance(latitude1, longitude1, latitude2, longitude2) returns 5
hours(dateTime) Returns numeric hour of the day for the given date. If date_time is 3:30 PM on Aug 31, 2005, hour(dateTime) returns 15
if() Returns one of two values depending on whether the result of evaluating a logical expression is true or false. if(xx>2, "big", "small")
includes(stringToLookIn, stringToFind) Takes two arguments and returns true if the second argument is a substring of the first (also treated as a string). includes("the", "he") returns true; includes("dancing", "joy") returns false; includes(1234, 23) returns true
join(delimiter, string1, string2,...,string99 ) Returns the string formed by concatenating its string arguments, each separated by its seperator argument.  join("/", m, d, y) returns a date in format "m/d/y"
last(attribute, filter)

Returns the value of that expression for the last case.

 

last(amountInBank) returns the last value of the attribute amountInBank

last(amountInBank, year>2010) returns the last value for the attribute amountInBank for which the year is greater than 2010

ln(number) Returns the logarithm of a number to base e. ln(100) is 4.61
log(number) Returns the logarithm of a number to base 10. log(100) is 2.0
linRegrSlope(xExpr, yExpr, filter) Computes the slope of the least squares regression line (lsrl) for two attributes.

linRegrSlope(fathers_height, sons_height) computes the slope of the lsrl for the two attributes.

linRegrSlope(age, height, age<18) computes the slope of the lsrl for age and height for those cases that have age less than 18.

linRegrIntercept(xExpr, yExpr, filter) Computes the y-intercept of the least squares regression line (lsrl) for two attributes.

linRegrIntercept(fathers_height, sons_height) computes the y-intercept of the lsrl for the two attributes.

linRegrIntercept(age, height, age<18) computes the y-intercept of the lsrl for age and height for those cases that have age less than 18.

linRegrResidual(xExpr, yExpr, filter) Returns the difference between the actual response and the predicted response from the least-squares regression line of the response values against the predictor values.

linRegrResidual(horsepower, mpg) returns, for each value of horsepower, the difference between the actual value of mpg and the predicted value.

linRegrPredicted(xExpr, yExpr, filter) Returns the response predicted by a least-squares regression line of the response values against the predictor values for each predictor value.

linRegrPredicted(horsepower, mpg) returns, for each value of horsepower, the the predicted value of mpg.

lookupBoundary(boundary_set, boundary_key)

Looks up a boundary, e.g. a country boundary, in an online collection. This boundary can be displayed on a map.

Possible values for the boundary_set include country_boundaries, US_state_boundaries, US_county_boundaries, US_congressional_boundaries, and US_puma boundaries.

The boundary_key will vary depending on the boundary_set. For countries use 2 or 3 letter country codes. For US states use full state name or USPS abbreviation. For US counties use a geo id as in 'usssccc'. US congressional districts are specified by 'usssdd'. Districts may be specified as the state abbreviation followed by district number as in CO01. CODAP will recognize the LASD (Legal

lookupBoundary(country_boundaries, "Canada") returns the boundary of Canada

lookupBoundary(US_state_boundaries, "GA") returns the boundary of the state of Georgia

lookupBoundary(US_county_boundaries, "Amador, CA") returns the boundary of Amador county in California

lookupBoundary(US_congressional_boundaries, "Kansas 03") returns the boundary of Kansas' 3rd district

lookupBoundary(US_puma_boundaries, "G2300100") returns the boundary of the southernmost PUMA in Maine

lookupByIndex("otherDataSetName", "remoteAttributeName", index) Returns the value of the specified attribute for the case at the specified (1-based) index in the data set name. Note that dataSetName and attributeName must be strings (or expressions that evaluate to strings), while index should evaluate to an integer.

lookupByIndex("United_States", "Full_state_name", index) looks up the attribute Full_state_name in the United_States data set at the index point.

It then returns Full_state_name in your data set.

lookupByKey("otherDataSetName", "returnedAttributeName", "keyAttributeName", keyValue) Returns the value of the specified returned attribute for the case with the specified keyValue as its value for the keyAttributeName attribute in the specified data set. 

lookupByKey("United_States", "State_abbreviations1", "State_abbreviations2", Full_state_name) looks up the states in the data set "United_States."

The attribute "State_abbreviations1" from the first data set matches the attribute "State_abbreviations2" from the second data set.

The function looks up the states "CA," "WA," "OR" and returns "California," "Washington," "Oregon."

max(expression, filter) Returns the maximum value of its argument evaluated for every case. 

max(100) returns 100

max(Height) returns the maximum height

mean(expression, filter) Returns the arithmetic mean (sum divided by count) of its argument evaluated for every case.

mean(height) computes the mean of the attribute height

mean(height, Sex = "F") computes the mean height of females

median(expression, filter) Returns the median. Half the values of the attribute will be above this and half will be below. median(lifetime) would return the median value for the attribute lifetime
min(expression, filter) Returns the minimum numeric value for an expression. An optional filter as a second parameter can limit the computation for certain cases.

min(price) returns the minimum value of the attribute price

min(price, quality = "good") gives the minimum value of price for cases that has quality good

minutes(dateTime) Returns the minute of the hour corresponding to the given date_time.  If date_time is 3:30 PM on Aug 31, 2005, minutes(dateTime) returns 30
month(date) Returns the number of the month corresponding to the given date.

If the date is Aug. 31, 2016, month(date) returns 8

monthName(date) Returns the long name of the month corresponding to the given date. If date is Aug 31, 2005, monthName(date) returns "August"
next(expression, default, filter) Returns the value of that expression for the next case.

next(number) is 10

next(number, City="Tucson") returns the next value for the attribute number for which the attribute City is Tucson

number(number)  Converts the input value to a numeric value. number(3.5) returns the number 3.5
patternMatches(string_to_look_in, pattern ) Returns the number of times in string_to_look_in the string or regular expression represented by pattern occurs. The search is case insensitive.

patternMatches("How many pickles can Peter Piper pick?", "pick") returns 2

patternMatches("June 25, 2020", "[0-9]") returns 6 because there are 6 digits

patternMatches("From June to July", "june|july") returns 2

percentile(expression, constant) Takes two arguments, the first being the attribute for which the percentile will be computed and the second the desired percentile expressed as a decimal fraction between 0 and 1. The second argument should be a constant, not an attribute. If it is an attribute, the value of that attribute for the first case will be used. percentile(speed, 0.5) is another way to compute the median
percentile(score, 0.95) will return the score corresponding to the 95th percentile.
pow(number, power) Returns the value of its argument rounded to the specified number of decimal places (default 0). pow(2,5) returns 32
prev(expression, default, filter) Returns the value of that expression for the previous case.

prev(height) returns 9

prev(height, sex="female") returns the previous value for the attribute height for which the attribute sex is female

random()

random(max)

random(min, max)

Returns a random number drawn from a uniform distribution.

random() returns a number between 0 and 1

random(100) returns a number between 0 and 100

random(–10, 10) returns a number between –10 and 10

randomBinomial(n, p)

Returns a random integer drawn from a binomial distribution with n independent draws (or experiments) each with probability p of success.

randomBinomial(5, 0.5) yields a number of heads in 5 flips of a fair coin

randomBinomial(2, 0.1) gives a random number representing the number of red poker chips in two draws from a bag containing 1 red and 9 blue poker chips

randomNormal(mean, standard_deviation)

Returns a random number drawn from a normal distribution which, by default, has a mean of 0 and a standard deviation of 1.

randomNormal() returns a number drawn from a normal distribution with a mean of 0 and a standard deviation of 1

randomNormal(100) returns a number drawn from a normal distribution with a mean of 100 and a standard deviation of 1

randomNormal(–10, 5) returns a number drawn from a normal distribution with a mean of -10 and a standard deviation of 5

randomPick()

Given a list of arguments, chooses one at random and returns it.

randomPick(1,2,3,4,5,6) makes a die, returning one of the number 1–6 chosen at random.

randomPick("heads","tails") makes a fair coin, returning either heads or tails.

randomPick("Male", "Male", "Female") gives you a population to draw from that is two-thirds Male.

randomPick(GirlsName, BoysName) randomly picks either the value of attribute GirlsName or attribute BoysName. For example, it might pick Ismail one time and Joyce another.

repeatString(aString, numRepetitions) Takes two arguments, the first a string and the second an integer ≥ 0. Returns the result of concatenating aString numRepetitions times.  repeatString("#&", 4) returns “#&#&#&#&”
replaceChars(aString, start, numChars, substituteString) Takes four arguments. The first is the original string. The second is an integer > 0 specifying the starting location for the substitution. The third is the number of characters to be replaced, and the last is the string that is to be substituted. If numChars is 0, substituteString is inserted. replaceChars("computer", 3, 4, "nfus") gives “confuser”.
replaceString(aString, stringToFind, substituteString) Takes three string arguments and substitutes the third for all occurrences of the second in the first. replaceString("12:30:45", ":", " and ") returns “12 and 30 and 45”
rSquared(xExpr, yExpr, filter) Computes square of the correlation coefficient for two attributes. The result does not depend on order.

rSquared(fathers_height, sons_height) computes the square of the correlation coefficient for the two attributes.

rSquared(age, height, age<18) computes the rSquared value for age and height for those cases that have age less than 18.

round(number, digits)

round(number, places)

Returns the value of its argument rounded to the specified number of decimal places (default 0). This function has an optional, second argument that specifies how many decimals to round to: round(3.14) is 3, round(π, 4) is 3.1416, and round(1234, –2) is 1200.
seconds(dateTime) Returns the second corresponding to the given date_time.  If dateTime is 3:30:05 PM on Aug 31, 2005, second(dateTime) returns 5.

sin(rad)

Returns the angle in radians that corresponds to the specified sine value [–1, 1]. sin(pi/2) returns 1
split(aString, seperator, index)

Returns the string formed by splitting a string by the specified separator and then returning the element at the specified index. 

Given an attribute “d” that contains strings of the form “mm/dd/yyyy”, split(d,”/",1) returns the month, split(d,”/“,2) returns the day, and split(d,”/“,3) returns the year.

split(09/01/2016, "/", 1) returns 09 

sqrt(number) Returns the square root of its numeric argument. sqrt(100) returns 10
stdDev(number) Computes the sample standard deviation. stdDev(pressure) computes the sample standard deviation of the attribute pressure
string(number) Returns the value of its argument converted to a string. string(6) is the string 6
stringLength(string) Returns the number of characters in the string representation of the argument. stringLength("Fathom") gives 6 stringLength(321) gives 3 
subString(string, position, length)  Returns a substring of the specified string, determined by its position and length arguments. substring(abcd,2,3) returns bcd
sum(number, filter) Returns the sum of its argument evaluated for every case.

sum(grade_point) computes the sum of the grade points

sum(Mass, Height>60) returns the sum of the masses for heights taller than 60

tan(radians) Returns the angle in radians that corresponds to the specified tangent value [–1, 1]. tan(pi/4) returns 1
today() Returns the current date as determined by the computer.  
toLower(string) Converts upper-case characters in its argument to lower-case. toLower(String) returns string 
toUpper(string) Converts lower-case characters in its argument to upper-case.  toUpper(String) returns STRING
trim(string) Removes leading, trailing, and redundant white space characters from its argument. (e.g. double spaces are converted to single spaces).  
trunc(number) Returns the nearest integer equal to or smaller in magnitude (closer to zero) than its argument. trunc(5.5) returns 5
uniqueValues(expression, filter) Returns the number of unique values produced by the expression.

uniqueValues(State) returns the number of unique values of the attribute State. If all state names are present, the result would likely be 50.

uniqueValues(Age, Sex="male") returns the number of different ages for the cases whose value of Sex is "male".

variance(expression) Computes the variance of an attribute, that is, the square of the standard deviation. variance(before–after) computes the variance of the difference of the two attributes before and after.
wordListMatches(string_to_look_in, "datasetName", "wordListAttributeName", "ratingsAttributeName" (optional)) Returns the total number of times any of the words in a given word list is found in the given strToLookIn. If the (optional) name of a numeric rating attribute is specified, the sum of the ratings for the found words is returned. Note that the search is performed with case insensitivity. If an entry in the word list begins and ends with "/" it is treated as a regular expression and searched for with case sensitivity.

Assume a dataset named "Short Words" has an attribute named "word" whose values are "a", "the", and "on".

wordListMatches("a party on a Monday", "Short Words", "word") returns 3 because "a" occurs twice, "the" does not occur, and "on" occurs once.

Suppose the "Short Words" dataset also has an attribute named "rating" whose are 4, 2, and 5.

wordListMatches("a party on a Monday", "Short Words", "word", "rating") returns 13 as the sum of the ratings for each word each time it is found.

Suppose the "word" attribute has one value which is "/a/". Then wordListMatches("a party on a Monday", "Short Words", "word") returns 4 since there are 4 occurrences of "a".

year(date) Returns the year corresponding to the given date. If date is Aug 31, 2005, year(date) returns 2005
Was this Article Useful? 

Comments

I think there is a typo in the mean formula. Wouldn't mu be used in a normal distribution function?

Hi, Katie, thanks for the catch. I updated the mean documentation for this page to be more clear.

How do you write a function to add values for cases across multiple attributes? For example, if Attribute A = number of brothers in family and if Attribute B = number of sisters in family, how would you write a function for a new attribute that would return the number of children in family (A + B)?

Good afternoon, Sarai,

Try creating a new attribute, C. Use the formula, sum. So, in the case of your example, the formula would be sum(A+B).

If you have additional questions, please post them in our Help Forums at https://codap.concord.org/forums/

How about computing the MAD and IQR? Do you have those functions?

For the MAD, in the Formula box simply type mad(attribute) and you should be able to calculate it. For the IQR, I'd create a univariate plot, then in the Measurement palette select Standard Deviation. You can then subtract the first quartile from the third.

Add new comment

Comments are closed for the CODAP Help site. If you have a question or problem, please post on the CODAP Help Forum instead. Thank you.