R - Names

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.

Management

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

Update

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

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

Set

example with a list

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

$age
[1] 40

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

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"

Documentation / Reference

?names

Powered by ComboStrap