gpt4 book ai didi

r - 将文本转换为表格,分隔符为#

转载 作者:行者123 更新时间:2023-12-01 07:25:23 24 4
gpt4 key购买 nike

我正在努力将我的文本文件转换为 R 中的表格。问题是列用“#”分隔,但是当我使用 read.table() 时功能与 sep="#"它看起来仍然不像一个普通的表并返回大量错误。

我该如何解决这个问题?

文本文件如下所示:

Hotel Van Walsum#121800#3#4.2#70#0.7 miles to City centre?#
Bilderberg Parkhotel Rotterdam#124547#4#3.7#83#0.5 miles to City centre?#
NH Atlanta Rotterdam#208643#4#3.9#55#0.3 miles to City centre?#
Nhow Rotterdam#439534#4#4.3#83#1.3 miles to City centre?#
The Manhattan Hotel Rotterdam#173187#5#4.5#101#0.1 miles to City centre?#
Mainport#427255#5#4.7#112#0.8 miles to City centre?#
easyHotel Rotterdam City Centre#438095#2#3.8#49#0.5 miles to City centre?#
ss Rotterdam Hotel & Restaurants#277518#4#4.3#84#1.8 miles to City centre?#
H2otel#276462#3#4.1#67#0.7 miles to City centre?#
Van der Valk Hotel Rotterdam-Blijdorp#272914#4#4.1#71#1.4 miles to City centre?#
NH Capelle#139024#4#4.1#55#4.5 miles to City centre?#
The Student Hotel Rotterdam#434163#3#4.2#62#1.3 miles to City centre?#
Novotel Rotterdam Brainpark#124868#4#4.4#69#2.4 miles to City centre?#
Hotel Van Walsum#121800#3#4.2#70#0.7 miles to City centre?#
Hampshire Hotel - Savoy Rotterdam#115253#4#3.7#65#0.8 miles to City centre?#
Delta Hotel Rotterdam#179050#4#4.2#80#5.8 miles to City centre?#
Novotel Rotterdam Schiedam#144828#4#4.3#69#4.2 miles to City centre?#
Hotel Rotterdam#209923#4#3.7#74#0.4 miles to City centre?#

最佳答案

我们需要在 read.table 中指定字段分隔符和注释字符:

read.table("myFile.txt", sep = "#", comment.char = "")

关于r - 将文本转换为表格,分隔符为#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32763442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com