Rsetdf
Rsetdf |
Purpose
Synopsis
procedure Rsetdf(dst:string, arr:array of boolean|integer|real|string)
Synopsis
procedure Rsetdf(dst:string, arr:array of boolean|integer|real|string, cname:list of string)
Arguments
dst
|
An R variable name
|
arr
|
The Mosel array to be assigned to
dst
|
cname
|
List of names to be assigned to the data.frame columns
|
Example
The following:
declarations CITIES = {"LONDON", "NEW YORK", "ROME"} ZONES = 1..4 myarray: dynamic array(ZONES, CITIES) of integer end-declarations myarray(1,'LONDON') := 8 myarray(1,'ROME') := 3 myarray(2,'NEW YORK') := 9 Rsetdf("a_df", myarray, ['Zone','City','Value']) Rprint("a_df")
produces this output:
Zone City Value 1 1 LONDON 8 2 1 ROME 3 3 2 NEW YORK 9
Further information
1. A new R data.frame is created from
arr and assigned to
dst
2. The argument
dst can represent any assignable expression (including subsetting and attributes).
3. The R data.frame is constructed with
n+1 columns (where
n is the number of dimensions of
arr): one column for each of the array's indices, plus one column for the array's values; and one row for each existing value of the array.
4. Rows are numbered from 1 to the number of existing values of
arr and column names are taken from the
cname argument, when given.
5. Only the first
n+1 strings from
cname are used; if
cname is shorter, then the right-most columns are left unnamed.
Related topics