I have a text file that can be read as:
file=read.table("C:\\data.txt", sep="")
> class(file)
[1] "data.frame"
> head(file)
name bat cat co ro
1 face 2 16 25 96
I have many text files in a directory that can be listed as:
dir<- list.files("C:\\datasets", "*.txt", full.names = TRUE)
the files are named like this:
ds_ds_df_2011_ 25_96.txt
this corresponds to:
ds_ds_df_2011_ co_ro.txt # co ro change while the rest is the same in all files.
where co
is file$co
and ro
is file$ro
.
What I need is to add the corresponding name
from file$name
to the files names to become:
ds_ds_df_2011_ co_ro_name.txt
is this possible?