Dear R-helpers, hello I am seeking your help in somehow getting names of variables without quotes (" "). Let us say, we have a table with 3 variables V1, V2 and V3. After the table is read, I get names of the variables (thro' the following code) as under quotes (like "V1" rather than the original representation V1) x=read.table("sample.txt",header=T,sep="\t")> xV1 V2 V3 1 15 10 4 2 6 4 7 3 10 5 2 4 8 6 6> nm=names(x) > nm[1] "V1" "V2" "V3" In fact I need the variables in the original representation (i.e., as they appear in the input data file) so as to use them repeatedly (through loop statement) in regression analysis. Kindly help. Regards ajss d Now! http://messenger.yahoo.com/download.php [[alternative HTML version deleted]]
Amarjit Singh Sethi <set_alt <at> yahoo.co.in> writes:> I am seeking your help in somehow??getting names of variables without quotes(" ").> Let us say,??we have a table with 3 variables V1, V2 and V3. After the tableis read, I get names of the> variables??(thro' the following code) as under quotes (like "V1"??rather thanthe original> representation V1) > ?? > ??x=read.table("sample.txt",header=T,sep="\t") > > x > ?????? V1?????? V2?????? V3 > 1?? 15???????? 10?????????? 4Please re-upload your problem without using HTML mail, at least for me it is not readable. Dieter
Dear AJSS, Perhaps ?noquote might be useful for you. Here is an example:> x=c('V1','V2','V3','V4') > x[1] "V1" "V2" "V3" "V4"> noquote(x)[1] V1 V2 V3 V4 HTH, Jorge On Sat, Oct 18, 2008 at 3:04 PM, Amarjit Singh Sethi <set_alt@yahoo.co.in>wrote:>  > Dear R-helpers, > hello > I am seeking your help in somehow getting names of variables without > quotes (" "). > Let us say, we have a table with 3 variables V1, V2 and V3. After the > table is read, I get names of the variables (thro' the following code) as > under quotes (like "V1" rather than the original representation V1) >  >  x=read.table("sample.txt",header=T,sep="\t") > > x >    V1   V2   V3 > 1 15    10     4 > 2   6      4      7 > 3 10     5      2 > 4   8     6      6 > > nm=names(x) > > nm > [1] "V1" "V2" "V3" >  > In fact I need the variables in the original representation (i.e., as they > appear in the input data file) so as to use them repeatedly (through loop > statement) in regression analysis. Kindly help. > Regards > ajss > > > > > d Now! http://messenger.yahoo.com/download.php > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >[[alternative HTML version deleted]]
On Sun, 19 Oct 2008, Amarjit Singh Sethi wrote:> ?? > Dear R-helpers, > hello > I am seeking your help in somehow??getting names of variables without quotes (" "). > Let us say,??we have a table with 3 variables V1, V2 and V3. After the table is read, I get names of the variables??(thro' the following code) as under quotes (like "V1"??rather than the original representation V1) > ?? > ??x=read.table("sample.txt",header=T,sep="\t") >> x > ?????? V1?????? V2?????? V3 > 1?? 15???????? 10?????????? 4 > 2???? ??6????????????4???????????? 7 > 3?? 10?????????? 5???????????? 2 > 4?????? 8?????????? 6???????????? 6 >> nm=names(x) >> nm > [1] "V1" "V2" "V3" ??In fact I need the variables in the > original??representation (i.e., as they appear in the input data file) > so as to use them repeatedly (through loop statement) in regression > analysis. Kindly help. Regards ajssI'll second Dieter's comment about HTML mail... ARGH!! But I will also hazard a guess that you are not going to solve your problem by forcing "V1" to print without quotes. Rather, you should check out ?as.formula Pay special attention to the last case in example( as.formula ) HTH, Chuck> > > > > d Now! http://messenger.yahoo.com/download.php > [[alternative HTML version deleted]] > >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
Dear AJSS, Perhaps: # ------------------- # Data set # ------------------- mydata=read.table(textConnection(" V1 V2 V3 1 15 10 4 2 6 4 7 3 10 5 2 4 8 6 6"),header=TRUE) closeAllConnections() # ------------------- # Regression models # ------------------- # Combinations library(forward) comb=t(fwd.combn(colnames(mydata),2)) # Summaries res=apply(comb,1,function(x){ y1=mydata[,x[1]] x1=mydata[,x[2]] m=lm(y1~x1) summary(m) } ) names(res)= apply(comb,1,paste,collapse="/",sep="") # Output in an external file sink("C:/out.txt") res sink() HTH, Jorge On Sun, Oct 19, 2008 at 11:38 AM, Amarjit Singh Sethi <set_alt@yahoo.co.in>wrote:> Dear Jorge/Dieter > Thank you very much for your help. I indeed have been able to get names of > the variables through 'noquote( )'statement. Yet my problem (regarding > running regression analysis iteratively: of V1 upon V2; of V1 upon V3; and > of V2 upon V3) could not be solved. My input data: > > V1 V2 V3 > 1 15 10 4 > 2 6 4 7 > 3 10 5 2 > 4 8 6 6 > I tried the following code: > x=read.table("sample.txt",header=T,sep="\t") > sink("out.txt") > for (i in 1:2){ > dep=noquote(nm[i]) > for(j in i+1:3){ > ind=noquote(nm[j]) > slr=lm(dep ~ ind, data=x) > smr=summary(slr) > smr > } > } > sink() > But I could not get any results. Kindly help or suggest suitable > alternative. > The data and the code are given as attachments also. > Regards > ajss > > > --- On *Sun, 19/10/08, Jorge Ivan Velez <jorgeivanvelez@gmail.com>* wrote: > > From: Jorge Ivan Velez <jorgeivanvelez@gmail.com> > Subject: Re: [R] Getting names of variables without quotes > To: set_alt@yahoo.co.in > Cc: r-help@r-project.org > Date: Sunday, 19 October, 2008, 1:04 AM > > > > Dear AJSS, > Perhaps ?noquote might be useful for you. Here is an example: > > > x=c('V1','V2','V3','V4') > > x > [1] "V1" "V2" "V3" "V4" > > noquote(x) > [1] V1 V2 V3 V4 > > HTH, > > Jorge > > > On Sat, Oct 18, 2008 at 3:04 PM, Amarjit Singh Sethi <set_alt@yahoo.co.in>wrote: > >>  >> Dear R-helpers, >> hello >> I am seeking your help in somehow getting names of variables without >> quotes (" "). >> Let us say, we have a table with 3 variables V1, V2 and V3. After the >> table is read, I get names of the variables (thro' the following code) as >> under quotes (like "V1" rather than the original representation V1) >>  >>  x=read.table("sample.txt",header=T,sep="\t") >> > x >>    V1   V2   V3 >> 1 15    10     4 >> 2   6      4      7 >> 3 10     5      2 >> 4   8     6      6 >> > nm=names(x) >> > nm >> [1] "V1" "V2" "V3" >>  >> In fact I need the variables in the original representation (i.e., as >> they appear in the input data file) so as to use them repeatedly (through >> loop statement) in regression analysis. Kindly help. >> Regards >> ajss >> >> >> >> >> d Now! http://messenger.yahoo.com/download.php >> [[alternative HTML version deleted]] >> >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide..html> >> and provide commented, minimal, self-contained, reproducible code. >> >> > > Send free SMS to your Friends on Mobile from your Yahoo! Messenger. > Download Now! http://messenger.yahoo.com/download.php[[alternative HTML version deleted]]
Amarjit Singh Sethi <set_alt <at> yahoo.co.in> writes: (Please do not use tabs when sending a data sample, these must be manually edited) V1,V2,V3 15,10,4 6,4,7 10,5,2 8,6,6 This does the work. However, I fear that you are going to use it on 100 variables, and I would strongly advice againts searching for linear relations that way. Dieter x=read.table("sample.txt",header=T,sep=",") nm = names(x) for (i in 1:2) { for(j in (i+1):3) # note that you need the ()! { formula= as.formula(paste(nm[i],"~",nm[j],sep="")) slr=lm(formula, data=x) smr=summary(slr) print(smr) } }