Stataq
Stataq

Reputation: 2301

how to rename one dataframe in a list

How to rename b to newname only? I tries names(lst[2])="newname" and it doesn't work.

lst <- list(a="one", b="two", c=c(1:3))

Upvotes: 1

Views: 283

Answers (1)

akrun
akrun

Reputation: 886938

Extract the names, then subset with index and assign

names(lst)[2] <- "newname"

Though, we can extract the names (getter) with

names(lst[2])
[1] "b"

The assignment (setter -names<-) should be on the whole object and not on the subset of the object

Upvotes: 1

Related Questions