benji
2012-Jul-17 15:08 UTC
[R] How to use a text in an object of class character position to create a vector with the text as name
Hello,>titletool<-read.csv("TotalCSVData.csv",header=FALSE,sep=",")> class(titletool)[1] "data.frame">titletool[1,1][1] Experiment name : CONTROL DB AD_1>t<-titletootl[1,1]>t[1] Experiment name : CONTROL DB AD_1>class(t)[1] "character" now i want to create an object (vector) with the name "Experiment name : CONTROL DB AD_1" , or even better if possible CONTROL DB AD_1 Thank you -- View this message in context: http://r.789695.n4.nabble.com/How-to-use-a-text-in-an-object-of-class-character-position-to-create-a-vector-with-the-text-as-name-tp4636755.html Sent from the R help mailing list archive at Nabble.com.
Sarah Goslee
2012-Jul-17 15:55 UTC
[R] How to use a text in an object of class character position to create a vector with the text as name
In general, you use assign() to do that, but having object names containing spaces should be avoided.> mytext <- "Experiment name : CONTROL DB AD_1" > mytext[1] "Experiment name : CONTROL DB AD_1"> mytext <- sub("Experiment name : ", "", mytext) > mytext[1] "CONTROL DB AD_1"> > assign(mytext, 1:10) > ls()[1] "CONTROL DB AD_1" "mytext"> "CONTROL DB AD_1"[1] "CONTROL DB AD_1"> > > CONTROL DB AD_1Error: unexpected symbol in "CONTROL DB" Since you can't access your object by typing its name at the R prompt, either with or without quotes, you've kind of got a problem. You could use get(), but at that point why not just name your object something that follows the R naming conventions? Sarah On Tue, Jul 17, 2012 at 11:08 AM, benji <benlucas at illinois.edu> wrote:> Hello, >>titletool<-read.csv("TotalCSVData.csv",header=FALSE,sep=",") > >> class(titletool) > [1] "data.frame" > >>titletool[1,1] > [1] Experiment name : CONTROL DB AD_1 > >>t<-titletootl[1,1] > >>t > [1] Experiment name : CONTROL DB AD_1 > >>class(t) > [1] "character" > > now i want to create an object (vector) with the name "Experiment name : > CONTROL DB AD_1" , or even better if possible CONTROL DB AD_1 > > Thank you >-- Sarah Goslee http://www.functionaldiversity.org