我希望在textConnection R中使用和scan将粘贴的字符数据集切换到字符向量作为row.names。我的小例子如下:
x = textConnection('
Arcadia
Bryce Canyon
Cuyahoga Valley
Everglades
Grand Canyon
Grand Teton
Great Smoky
Hot Springs
Olympic
Mount Rainier
Rocky Mountain
Shenandoah
Yellowstone
Yosemite
Zion
')
scan(x,character(0)) 数据集的每一行代表一个位置,因此,它应该有一个长度为15的字符向量。
Read 23 items
[1] "Arcadia" "Bryce" "Canyon" "Cuyahoga" "Valley"
[6] "Everglades" "Grand" "Canyon" "Grand" "Teton"
[11] "Great" "Smoky" "Hot" "Springs" "Olympic"
[16] "Mount" "Rainier" "Rocky" "Mountain" "Shenandoah"
[21] "Yellowstone" "Yosemite" "Zion" 然后我尝试了scan(x,character(0),seq='\n'),但它也不起作用!有什么帮助吗?
发布于 2020-03-01 08:05:30
由于输入引用,我们应该指定参数sep (而不是seq!)如果我们希望scan使用‘非空白’作为分隔符。来自?scan
默认情况下,
sep期望读取“空格”分隔的输入字段.或者,sep可用于指定分隔字段的字符。除非引用字段,否则字段总是由行尾标记分隔.如果指定的话,这应该是空字符串(默认)或NULL,或者只包含一个单字节字符的字符串。
x = textConnection('
Arcadia
Bryce Canyon
Cuyahoga Valley
Everglades
Grand Canyon
Grand Teton
Great Smoky
Hot Springs
Olympic
Mount Rainier
Rocky Mountain
Shenandoah
Yellowstone
Yosemite
Zion
')
scan(x,character(0), sep="\n") 返回:
阅读了15项"Arcadia“、"Bryce Canyon”、"Cuyahoga Valley“、”大沼泽地“、5”大峡谷“、"Grand Teton”、"Great“、”温泉“、”奥林匹克“、”Rainier山“、"Rocky Zion”、"Shenandoah“、13”黄石“、"Yosemite”、“
”
https://stackoverflow.com/questions/60471789
复制相似问题