0

I am writing a simple R script (script.r).

I want R to read in 13 serially numbered tables ("table1.txt", "table2.txt", etc.), then select a particular column ("dosage"), and multiply each of the 13 outputs by a different factor, and then sum them all at the end.

for (i in 1:13) {
    loci[i]<-read.table("table[i].txt, header=T)
    dloc[i]<-(loc[i]$dosage)
    logdloc1<-(dloc1*0.077)
    logdloc2<-(dloc2*-0.105)
    logdloc3<-(dloc3*0.104)
    logdloc4<-(dloc4*0.113)
    logdloc5<-(dloc5*-0.105)
    logdloc6<-(dloc6*0.131)
    logdloc7<-(dloc7*-0.117)
    logdloc8<-(dloc8*-0.083)
    logdloc9<-(dloc9*-0.083)
    logdloc10<-(dloc10*0.182)
    logdloc11<-(dloc11*0.157)
    logdloc12<-(dloc12*0.086)
    logdloc13<-(dloc13*0.27)
    output<-(logdloc1 + logdloc2 + logdloc3 + logdloc4 + logdloc5 + logdloc6 + logdloc7 + logdloc8 + logdloc9 + logdloc10 + logdloc11 + logdloc12 + logdloc13)}

I know there's a syntax error, because I get an error message when I try to execute it in command line:

Rscript script.r
Error: unexpected end of input

Can somebody very kindly spot the obvious?

Very grateful for your help.

AB

1 Answer 1

2

You have a missing "

for (i in 1:13) {
    loci[i]<-read.table("table[i].txt", header=T)
    dloc[i]<-(loc[i]$dosage)
    logdloc1<-(dloc1*0.077)
    logdloc2<-(dloc2*-0.105)
    logdloc3<-(dloc3*0.104)
    logdloc4<-(dloc4*0.113)
    logdloc5<-(dloc5*-0.105)
    logdloc6<-(dloc6*0.131)
    logdloc7<-(dloc7*-0.117)
    logdloc8<-(dloc8*-0.083)
    logdloc9<-(dloc9*-0.083)
    logdloc10<-(dloc10*0.182)
    logdloc11<-(dloc11*0.157)
    logdloc12<-(dloc12*0.086)
    logdloc13<-(dloc13*0.27)
    output<-(logdloc1 + logdloc2 + logdloc3 + logdloc4 + logdloc5 + logdloc6 + logdloc7 + logdloc8 + logdloc9 + logdloc10 + logdloc11 + logdloc12 + logdloc13)}

Edit

Based on coment, i guess that table is an r object so you should replace this line by:

loci[i]<-read.table(paste0(table[i], ".txt"), header=T)

which will paste the ith element to ".txt".

For a more complete answer, please precise what is in table

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you - that was very sloppy of me. Have now executed with the " in place. But I am now encountering another error message: "cannot open file 'table[i].txt': No such file or directory". Even though I have table1.txt to table13.txt within that directory. Why could this be? Thank you.
I eddited answer please check it and complete your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.