[R] Troubleshooting code

Peter Ehlers ehlers at ucalgary.ca
Tue Mar 12 18:44:31 CET 2013


On 2013-03-12 05:29, Sahana Srinivasan wrote:
> Hi everyone, I am having trouble understanding where I went wrong with my
> code. It seems to logically be "all there"  but the output says otherwise.
> I know this is a bit long but I can't seem to find the errors so I would
> appreciate your help :)
>
> This is my program :
>
> files<-Sys.glob("*.rescount.txt");length<-length(files);* #selecting all
> files of a particular extension, saving in a list*

Your use of the name 'length' is a bad idea (but not your problem);
see fortune("dog").

If you think that your object 'files' is a 'list', you're mistaken;
try  str(files)  to see that it's a character vector.

> a<-1;
> while(a<=length) *#going through every element of the list*
> {
>    df1<-read.table(files[a]);

I would _always_ look at the result of any file import with str() to
ensure that the reading went as expected. Do (some of) your files have
variable variable name headers?

>    c.leng<-length(files[,1]);

I don't see why this instruction would not throw an error re "incorrect
number of dimensions".

Okay, at this point I gave up. Your code is not reproducible and
you're posting in HTML. Please give at least a cursory look at the
Posting Guide.

   [... rest of code sample snipped ...]

Peter Ehlers



More information about the R-help mailing list