[R] syntaxe problem
Peter Langfelder
peter.langfelder at gmail.com
Sat Feb 25 00:52:05 CET 2012
On Fri, Feb 24, 2012 at 3:47 PM, Adel ESSAFI <adelessafi at gmail.com> wrote:
> Hello,
> I want to create 10 dataframe using a for loop.
> I don t know what to do to create 10 different dataframes whose name is
> parametrized with variable i.
> This syntaxe fails. It create a unique fataframe called dfn.
> Any input will help
> Thanks
>
>> for (i in 1:10){
> + filename=paste("avail4",i,sep = "_")
> + dfn=read.table(filename)
> + }
You may want to create a list of 10 data frames.
dfn = list();
for (i in 1:10){
filename=paste("avail4",i,sep = "_")
dfn[[i]]=read.table(filename)
}
This way dfn[[1]] will be the data frame read from the first file,
dfn[[2]] from the second file etc.
Hope this helps,
Peter
More information about the R-help
mailing list