Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

From the following code:

var<-c("a","a","b","b","c","d")

I want to have something like this:

c("a"="a", "b"="b", "c"="c", "d"="d")

then like this

c("Whole a"="="a", "Whole b"="b", "Whole c"="c", "Whole d=","d")

"Whole a" means that I want to write complete names of the levels (beginning with a capital letter and having space between two words).

1 Answer

0 votes
by (108k points)

From your question, I think that you might want to create a named vector. Something like the following:

setNames(unique(var), paste('Whole', unique(var)))

#Whole a Whole b Whole c Whole d 

#    "a"     "b"     "c"     "d" 

If you are interested in R certification, then do check out the R programming certification.

Browse Categories

...