Suppose I have a vector of character strings that I'd like to use to name new columns in a data.frame. I could do this:
my_strings = c("Some", "Strings", "Here")
for (i in my_strings) {
df[,i] = 1
}
And get three new columns in the df
name appropriately. But if instead I did
my_strings = c("Some", "Strings", "Here")
for (i in my_strings) {
df$i = 1
}
I'll just get one new column named "i". This isn't a problem with data frames but some objects are difficult or impossible to modify without using the $
operator - is there some way to feed it a variable to interpret as a character?