Reputation: 663
I have a dataframe:
inde.vars <- structure(list(Group = c("CUR", "CUR", "CUR", "CUR", "CUR", "CUR",
"CUR", "CUR", "CUR", "CUR"), Subject = c("0", "0", "0", "0",
"0", "0", "0", "0", "0", "0"), Condition = c("L1", "L1", "L1",
"L2", "L2", "L2", "L3", "L3", "L3", "L4"), Trial = c(1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L)), row.names = c(1L, 68L, 76L,
151L, 226L, 301L, 376L, 451L, 464L, 539L), class = "data.frame")
classes.group <- inde.vars[,1]
What do I need to do to assign object name or some identifier, for example, "Group" for character object classes.group
so I get someting like:
names(classes.group)
"Group"
Upvotes: 1
Views: 229
Reputation: 887118
If we need an attribute then we can have
attr(classes.group, 'name') <- 'Group'
classes.group
#[1] "CUR" "CUR" "CUR" "CUR" "CUR" "CUR" "CUR" "CUR" "CUR" "CUR"
#attr(,"name")
#[1] "Group"
We can extract with attributes
or attr
attr(classes.group, 'name')
#[1] "Group"
The issue with having a named
vector
when the vector
length
is greater than 1 is we need to rep
licate the value 'Group' to the entire length
Upvotes: 1
Reputation: 679
use names to assign a name to object. in general
names(object)<-c("ObjectDesiredName1","ObjectDesiredName2",..)
for your case:
names(classes.group)<-"Group" or
names(classes.group)<-c("Group")
Upvotes: 1