Kavitha Venkatesan
2010-Mar-20 21:07 UTC
[R] Converting a character string into a data frame name and performing assignments to that data frame
Hi, I would like to do the following operations: variable.df is a character string that contains the name of the data frame that I want to do the following operations on: variable.df <- data.frame(); # I can do the above command using assign( variable.df, data.frame() ) How can I perform the assignment statements below ? colnames(variable.df) = colnames(some.other.df) variable.df = rbind(variable.df, some.other.df) write.table(variable.df, file=some.file) Doing eval( substitute( colnames(var), list(var=as.name(variable.df) ) ) ) didn't get me all the way there. Thanks! Kavitha
Dieter Menne
2010-Mar-21 09:23 UTC
[R] Converting a character string into a data frame name and performing assignments to that data frame
Kavitha Venkatesan-2 wrote:> > variable.df is a character string that contains the name of the data > frame that I want to do the following operations on: > > variable.df <- data.frame(); > # I can do the above command using > assign( variable.df, data.frame() ) > > How can I perform the assignment statements below ? > > colnames(variable.df) = colnames(some.other.df) >Try to avoid assign and eval when you are not fiRm; the first is rarely used, and the second is a bit to powerful for safeR. data(iris) head(iris) names(iris) = c("A","B","C","D","Spec") head(iris) Dieter -- View this message in context: http://n4.nabble.com/Converting-a-character-string-into-a-data-frame-name-and-performing-assignments-to-that-data-frame-tp1676236p1676552.html Sent from the R help mailing list archive at Nabble.com.
Kavitha Venkatesan
2010-Apr-07 16:13 UTC
[R] Converting a character string into a data frame name and performing assignments to that data frame
Hi, I'd greatly appreciate any insight into the problem in my previous message below: Please note that I would like to loop through the following steps for a list of data frames whose names are dynamically assigned at run time, so I have a character string variable, called "variable.df", which stores the name of the data frame at any given point ...and I need to be able to manipulate the contents of the data frame somehow using this character string :> colnames(variable.df) = colnames(some.other.df) > variable.df = rbind(variable.df, some.other.df) > write.table(variable.df, file=some.file)Thanks! Kavitha On Sat, Mar 20, 2010 at 5:07 PM, Kavitha Venkatesan <kavitha.venkatesan at gmail.com> wrote:> Hi, > > I would like to do the following operations: > > variable.df is a character string that contains the name of the data > frame that I want to do the following operations on: > > variable.df <- data.frame(); > # I can do the above command using > assign( variable.df, data.frame() ) > > How can I perform the assignment statements below ? > > colnames(variable.df) = colnames(some.other.df) > variable.df = rbind(variable.df, some.other.df) > write.table(variable.df, file=some.file) > > Doing > eval( ?substitute( colnames(var), list(var=as.name(variable.df) ) ) ) > ?didn't get me all the way there. > > Thanks! > Kavitha >
Reasonably Related Threads
- Obtaining the value of x at a given value of y in a smooth.spline object
- applying a function to a pair of components for each row of a list
- split-apply question
- tapply with multiple arguments that are not part of the same data frame
- CentOS 7.2 rootfs for i386