R中导入文本文件

问题描述 投票:-1回答:1

我有一个文本文件中的数据。我的文本文件看起来像这样它导入到R的例子有问题:

孔:1必须:1 top_secret:1他:1中心:1个other_civilans:1 the_pacific:1 the_navy:1 a_lot:1个surface_must:1 this_book:1 man_named:1 _feet:2

有像上述数据的多条线路。这将是巨大的,如果有人可以帮助我解决这个!

提前致谢!!

我想在两列像要读取的文件

holes        1  
must         1
top_secret   1
r import text-files
1个回答
1
投票
x <- data.frame('name' = scan('input_file.txt', what = 'list', sep =' '))
x$name <- as.character(x$name)
x$value <- substr(x$name, start = nchar(x$name), stop = nchar(x$name))
x$name <- substr(x$name, start = 1, stop = nchar(x$name) - 2)
print(x)
             name value
1           holes     1
2            must     1
3      top_secret     1
4              he     1
5          center     1
6  other_civilans     1
7     the_pacific     1
8        the_navy     1
9           a_lot     1
10   surface_must     1
11      this_book     1
12      man_named     1
13     <num>_feet     2
© www.soinside.com 2019 - 2024. All rights reserved.