[R] Error creating named character vectors from column names in data frame.

Jorge Cimentada cimentadaj at gmail.com
Fri Oct 7 19:44:41 CEST 2016


Hi Bert,

Yes, I'm aware of the difference between a and "a" but in terms of object
classes I don't see the difference between "a" and names(mtcars)[1].
They're both strings. However, for creating a named character vector, this
works:

c("a" = "b)

But this doesn't

c(names(mtcars)[1] = "b")

For example:

df <- data.frame("a" = 1:5)
c("a" = "b")
c(names(df)[1] = "b") # error

But

identical(names(df)[1], "a")

That was my initial question.

	[[alternative HTML version deleted]]



More information about the R-help mailing list