Saving A Table In R With Its Own Name
1
0
Entering edit mode
11.1 years ago
Assa Yeroslaviz ★ 1.8k

Hi,

I would like to know, whether it is possible to read one table into R and use the name of the file also as an object name

This should look some thing like that:

tablename.txt <- read.delim2("tablename.txt", sep="\t")

But I would like to able to assign tablename.txt automatically, without me having to change it each time.

is it possible to do it with assign?

Thanks

Assa

r • 1.7k views
ADD COMMENT
3
Entering edit mode
11.1 years ago
Assa Yeroslaviz ★ 1.8k

Ok

I solved the problem.

It was possible by saving the list of files into R as list and than assign them each time to the read.table command as this:

list_names = as.list(dir(pattern="*.txt"))
assign(list_names[[1]], read.delim2("tablename.txt", sep="\t", skip=1))
ADD COMMENT
1
Entering edit mode

In case your first file in list_name is not tablename.txt

list_names = as.list(dir(pattern="*.txt"))
assign(list_names[[1]], read.delim2(list_names[[1]], sep="\t", skip=1))
ADD REPLY
1
Entering edit mode

You're right. it was a typing error. I meant that. thanks

ADD REPLY

Login before adding your answer.

Traffic: 2364 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6