DataSeries/SubsDatatype
change the datatype of a data series
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
SubsDatatype( DS, newdatatype, options )
DF
-
a DataSeries object
newdatatype
type; the new datatype for the data series
conversion : procedure; specifies a procedure to be mapped onto the elements in the given data series. This option is entered in the form conversion = procedure.
The SubsDatatype command changes the datatype of the entries in a DataSeries as well as the indicated datatype of the data series.
If the conversion option is given, then the values in the DataSeries are converted by this conversion procedure. Otherwise, they are typically not modified, but there are exceptions. Internally, a new Array is constructed with the given datatype, and the current values are used to initialize this Array; this is the step where an automatic conversion could take place.
Consider some data on berries.
genus≔DataSeries⁡Rubus,Vitis,Fragaria,labels=Raspberry,Grape,Strawberry,datatype=string:
energy≔DataSeries⁡220,288,136,labels=Raspberry,Grape,Strawberry,datatype=integer:
carbohydrates≔DataSeries⁡11.94,18.1,7.68,labels=Raspberry,Grape,Strawberry,datatype=float:
top_producer≔DataSeries⁡Russia,China,USA,labels=Raspberry,Grape,Strawberry,datatype=name:
The individual DataSeries are displayed more compactly in a DataFrame:
berries≔DataFrame⁡Energy=energy,Carbohydrates=carbohydrates,TopProducer=top_producer,Genus=genus
berries≔EnergyCarbohydratesTopProducerGenusRaspberry22011.9400000000000RussiaRubusGrape28818.1000000000000ChinaVitisStrawberry1367.68000000000000USAFragaria
You can get the data types for the columns with the Datatypes command.
Datatypes⁡berries
integer,float8,name,string
Datatype⁡carbohydrates
float8
You can change the datatype of the Energy data series to float:
SubsDatatype⁡energy,float
Raspberry220.Grape288.Strawberry136.
This does not change the datatype in place. To permanently change the datatype:
energy≔SubsDatatype⁡energy,float
energy≔Raspberry220.Grape288.Strawberry136.
Datatype⁡energy
When working with strings or name conversions, it may be necessary to supply an explicit conversion for the values in the data series:
genus≔SubsDatatype⁡genus,name,`=`⁡conversion,x↦convert⁡x,name
genus≔RaspberryRubusGrapeVitisStrawberryFragaria
Datatype⁡genus
name
top_producer≔SubsDatatype⁡top_producer,string,`=`⁡conversion,x↦convert⁡x,string
top_producer≔RaspberryRussiaGrapeChinaStrawberryUSA
Datatype⁡top_producer
string
berries≔EnergyCarbohydratesTopProducerGenusRaspberry220.11.9400000000000RussiaRubusGrape288.18.1000000000000ChinaVitisStrawberry136.7.68000000000000USAFragaria
float8,float8,string,name
The DataSeries/SubsDatatype command was introduced in Maple 2017.
For more information on Maple 2017 changes, see Updates in Maple 2017.
See Also
DataFrame/Datatypes
DataFrame/SubsDatatype
DataSeries/Datatype
Download Help Document