[R] Error creating named character vectors from column names in data frame.
Bert Gunter
bgunter.4567 at gmail.com
Fri Oct 7 19:34:21 CEST 2016
I think you have R semantics confused. What do you think
c("a" = "b")
means?
Note that:
> c("a" = "b")
a
"b"
> a
Error: object 'a' not found
And of course:
class("a") # character
class("b") # character
but this has *nothing* to do with the line immediately above it.
Have you gone through any basic R tutorials? There are many good ones
on the web.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Oct 7, 2016 at 9:06 AM, Jorge Cimentada <cimentadaj at gmail.com> wrote:
> Hi everyone,
>
> I was hoping someone would explain why this doesn't work.
>
> c("a" = "b") # named character vector
> class("a") # character
> class("b") # character
>
> c(names(mtcars)[1] = names(mtcars[2]) # error
> class(names(mtcars)[1]) # character
> class(names(mtcars)[2]) # character
>
>
> Thanks,
> Jorge Cimentada
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list