Friends

I can't quite find a direct answer to this question from the lists, so here 
goes:

I have several dataframes, 200+ columns 2000+ rows. I wish to script some 
operations to perform on some of the variables (columns) in the data frames not 
knowing what the column number is, hence have to refer by name. I have variable 
names in a text file "varlist". So, something like this:

for (i in 1:length(varlist)){
        j<-varlist[i]
        v<-mean(Dataset[[j]])
        print(v)
}

Now, if I force it

j<-"Var1"
v<-mean(Dataset[[j]])
print(v)

then it works, but not if i read the varlist as above. 

Looking at "j" I get:

> print(j)
          V1
1 Var1

Hence there is a lot of other stuff read into "j" that confuses "mean". I can't 
figure out how to just get the value of the variable and nothing else. I've 
tried space separated, comma separated, tab separated lists and all give the 
same error. I've tried get(), parse()... no go.

Any suggestions?

Thanks a lot

Jon

Soli Deo Gloria

Jon Erik Ween, MD, MS
Scientist, Kunin-Lunenfeld Applied Research Unit 
Director, Stroke Clinic, Brain Health Clinic, Baycrest Centre
Assistant Professor, Dept. of Medicine, Div. of Neurology
    University of Toronto Faculty of Medicine

Kimel Family Building, 6th Floor, Room 644 
Baycrest Centre
3560 Bathurst Street 
Toronto, Ontario M6A 2E1
Canada 

Phone: 416-785-2500 x3648
Fax: 416-785-2484
Email: jw...@klaru-baycrest.on.ca


Confidential: This communication and any attachment(s) may contain confidential 
or privileged information and is intended solely for the address(es) or the 
entity representing the recipient(s). If you have received this information in 
error, you are hereby advised to destroy the document and any attachment(s), 
make no copies of same and inform the sender immediately of the error. Any 
unauthorized use or disclosure of this information is strictly prohibited.




        [[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.

Reply via email to