[R] building data object on iteration
    Itay Furman 
    itayf at fhcrc.org
       
    Tue Mar 23 19:40:35 CET 2004
    
    
  
On Tue, 23 Mar 2004, Fred J. wrote:
> Hello
> I need help, few days tying to work this out but
> unable to find examples. "alos would appricate
> direction on how to find exmples"
> getting the file name "without the extension" into a
> character vector.
> for (i in dir("c:/data/")){
>     filename <- c(filename,sub("([^.]+)(\\..+)","\\1",
> i))
> }
> Error: Object "filename" not found
> and I understand why the error but cann't find a way
> to fix it.
> 
filename <- c()	#<--- Initialize. Needed for 1st iterataion.
for (i in dir("c:/data/")){
    filename <- c(filename,sub("([^.]+)(\\..+)","\\1",
i))
}
But as noted from another responder -- you don't need a loop.
	Itay
    
    
More information about the R-help
mailing list