R list names variable

The LISTNAMES program produces a report that lists the names of the objects in a workspace. You can limit the list to particular types of objects, and you can have the names for each type of object listed in alphabetical order.

Syntax

LISTNAMES [AW workspace|'*'] [objtype-list|ALL] -

     [SORTED|UNSORTED] [LIKE 'pattern']

Arguments

AW workspace AW '*'

Specifies the name of an attached workspace whose objects you want to list. When you omit the workspace name, LISTNAMES lists the objects in the current workspace. When you use the '*' [asterisk] argument instead of a workspace name, LISTNAMES produces a separate report for each attached workspace.

objtype-list ALL

Specifies one or more of the following types of objects whose names you want to list: AGGMAP, COMPOSITE, DIMENSION, FORMULA, MODEL, OPTION, PROGRAM, RELATION, VALUESET, VARIABLE, and WORKSHEET. You can include a trailing "S" on any object type, for example, DIMENSIONS. You can list these object types in any order. ALL [the default] specifies that the names of objects of all these types should be listed.

SORTED UNSORTED

SORTED [the default, abbreviated SORT] specifies that the object names should be sorted alphabetically. UNSORTED [abbreviated UNSORT] specifies that the object names should not be sorted alphabetically.

LIKE 'pattern'

Compares the names of the definitions in a workspace to the text pattern you specify and lists the names that match. A definition name is like a text pattern when corresponding characters match. Besides literal matching, LIKE lets you use wildcard characters to match more than one character in a string. An underscore [_] character in a pattern matches any single character. A percent [%] character in a pattern matches zero or more characters.

Examples

Example 16-27 Listing of DEMO Workspace Objects

This example lists the dimensions, variables, and relations in the current workspace. The statement

LISTNAMES dimension variable relation

produces the following output for the DEMO workspace.

10 DIMENSIONs 18 VARIABLEs 4 RELATIONs ---------------- ---------------- ---------------- DISTRICT ACTUAL DIVISION.PRODUCT DIVISION ADVERTISING MARKET.MARKET LINE BUDGET MLV.MARKET MARKET DEMOVER REGION.DISTRICT MARKETLEVEL EXPENSE MONTH FCST PRODUCT INDUSTRY.SALES QUARTER NAME.LINE REGION NAME.PRODUCT YEAR NATIONAL.SALES PRICE PRODUCT.MEMO SALES SALES.FORECAST SALES.PLAN SHARE UNITS UNITS.M

There are a number of functions for listing the contents of an object or dataset.

# list objects in the working environment
ls[]

# list the variables in mydata
names[mydata]

# list the structure of mydata
str[mydata]

# list levels of factor v1 in mydata
levels[mydata$v1]

# dimensions of an object
dim[object]

# class of an object [numeric, matrix, data frame, etc]
class[object]

# print mydata
mydata

# print first 10 rows of mydata
head[mydata, n=10]

# print last 5 rows of mydata
tail[mydata, n=5]

To Practice

Try the free first chapter of this course on cleaning data.

A list is an object in R Language which consists of heterogeneous elements. A list can even contain matrices, data frames, or functions as its elements. The list can be created using list[] function in R. Named list is also created with the same function by specifying the names of the elements to access them. Named list can also be created using names[] function to specify the names of elements after defining the list. In this article, we’ll learn to create named list in R using two different methods and different operations that can be performed on named lists.

Syntax: names[x]

Chủ Đề