R - Names

> Procedural Languages > R

1 - About

Language - Name (Program Entity) in R.

A name permits to address a value.

An object may have several values and then several names.

For a data.frame or a list, it will be the column header.

You can set and/or get them.

Advertising

3 - Management

3.1 - List

The available names of an object can be found with the names function:

names(x)

where:

The str function gives them also:

str(df)
'data.frame':	5 obs. of  3 variables:
 $ colA: int  1 2 3 4 5
 $ colB: int  2 3 4 5 6
 $ colC: int  3 4 5 6 7

3.2 - Update

The previous names are not really beautiful, we will change them:

names(df)=c("cond","diff")
> names(df)
[1] "cond" "diff"

3.3 - Set

example with a list

l = list(name = "Nico", age = 40)
l
$name
[1] "Nico"

$age
[1] 40

> names(l)
[1] "name" "age" 
Advertising

3.4 - Get the values by name

You may use the $ sign to retrieve a named value:

You can access the value by name

l$name
[1] "Nico"

4 - Documentation / Reference