Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In R, how can I set the names of an object and return it in one line?

Tags:

r

names

I would like to set the names of my R object and return it in one line. It should look something like:

names(doWork(), c("a", "b", "c"))

And perform the equivalent of:

x <- doWork()

names(x) <- c("a", "b", "c")

x

Is this possible?

like image 875
sdgfsdh Avatar asked Mar 17 '23 05:03

sdgfsdh


1 Answers

You can try setNames

x <- setNames(doWork(), letters[1:3])
like image 131
akrun Avatar answered Apr 07 '23 09:04

akrun