I'm trying to rename a column without creating an object (dataframe).
When I run:
names(data.frame(cbind(LETTERS[1:3],1:3)))[1]<-"A"
I get:
Error in names(data.frame(cbind(LETTERS[1:3], 1:3)))[1] <- "A" : could not find function "data.frame<-"
If I run:
X<-data.frame(cbind(LETTERS[1:3],1:3))
colnames(X)[1]<-"letters"
X
I'll see the column name changed because I made a data frame and then changed it. I'm pretty sure these two code snippets are the same except for the object creation. I don't know if R is just inflexible on this function and I have to create objects sometimes and not others. But the error "...could not find function" seemed a bit odd to me. Can someone explain this error?