我有一个中文小行星的数据集,加上相应的英文翻译,在这样的txt文件中:
三垣, Three Enclosures
紫微垣, Purple Forbidden Enclosure
太微垣, Supreme Palace Enclosure
天市垣, Heavenly Market Enclosure
四象, Four Symbols
青龍(東), Azure Dragon (East)
玄武(北), Murky Warrior (North)
白虎(西), White Tiger (West)
朱雀(南), Vermilion Bird (South)
二十八宿, Twenty-eight mansions
角, Horn
亢, Neck
氐, Root
房, Room
心, Heart
尾, Tail
箕, Winnowing-basket
斗, Dipper
牛, Ox
女, Girl
虛, Emptiness
危, Rooftop
室, Encampment
壁, Wall
奎, Legs
婁, Bond
胃, Stomach
昴, Hairy head
畢, Net
觜, Turtle beak
參, Three stars
井, Well
鬼, Ghosts
柳, Willow
星, Star
張, Extended net
翼, Wings
軫, Chariot
南極星區, Southern Sky
========
三垣, Three Enclosures
紫微垣, Purple Forbidden Enclosure
北極, Northern pole
太子, Crown prince
帝, Emperor
庶子, Son of Concubine
後宮, Imperial Concubine
天樞, Celestial pivot
四輔,Four Advisors
勾陳,Curved Array
天皇大帝,Great Emperor of Heaven
天柱,Celestial Pillar
御女,Maids-in-waiting
女史,Female protocol
柱史,Official of royal archives
尚書,Royal secretary
天床,Celestial bed
大理,Chief judge
陰德,Hidden virtue
六甲,Six Jia
五帝內座,Interior seats of five emperors
華蓋,Canopy of the emperor
杠,CanopySupport
紫微左垣,Left wall
左樞,Left pivot
上宰,First premier
少宰,Second premier
上弼,First minister
少弼,Second minister
上衛,First imperial guard
少衛,Second Imperial guard
少丞,Second prime minister
紫微右垣,Right Wall
右樞,Right pivot
少尉,Second chief judge
上輔,First minister
少輔,Second minister
上衛,First imperial guard
少衛,Second imperial guard
上丞,First prime minister
天乙(天一),Celestial Great One
太乙(太一),First Great one
內廚,Inner kitchen
北斗,Northern dipper
天樞,Celestial pivot
天璇,Celestial rotating jade
天機,Celestial shining pearl
天權,Celestial balance
玉衡,Jade sighting-tube
開陽,Opener of heat
搖光,Twinkling brilliance
輔,Assistant
天槍,Celestial spear
玄戈,Sombre lance
三公,Three excellencies
相,Prime minister
天理,Judge for nobility
太陽守,Guard of the Sun
太尊,Royals
天牢,Celestial prison
勢,Eunuch
文昌,Administrative centre
內階,Inner steps
三師,Three top instructors
八榖,Eight kinds of crops
傳舍,Guest house
天廚,Celestial kitchen
天棓,Celestial flail
太微垣, Supreme Palace Enclosure
五帝座,Seats of the five emperors
太子,Crown prince
從官,Retinue
幸臣,Officer of honour
五諸侯,Five feudal kings
九卿,Nine senior officers
三公,Three excellencies
內屏,Inner screen
太微左垣,Left wall
左執法,Left law administrator
東上相,First eastern minister
東次相,Second eastern minister
東次將,Second eastern general
東上將,First eastern general
太微右垣,Right wall
右執法,Right law administrator
西上將,First western general
西次將,Second western general
西次相,Second western minister
西上相,First western minister
郎將,Captain of the bodyguards
郎位,Official of imperial guard
常陳,Imperial guards
三台,Three steps
上台,Upper step
中台,Middle step
下台,Lower step
虎賁,Emperor's bodyguard
少微,Junior officers
長垣,Long wall
靈台,Astronomical observatory
明堂,Cosmological temple
謁者,Usher of the court
天市垣 , Heavenly Market Enclosure
帝座,Emperor's seat
候,Astrologer
宦者,Eunuch official
斗,Dipper for liquids
斛,Dipper for solids
列肆,Jewel market
車肆,Commodity market
市樓,Municipal office
宗正,Official for royal clan
宗人,Official of Religious Ceremonies
宗,Patriarchal clan
帛度,Textile ruler
屠肆,Butcher's shops
天市左垣,Left wall
魏,WEI
趙,ZHAO
九河,JIUHE
中山,ZHONGSHAN
齊,QI
吳越,WUYUE
徐,XU
東海,DONGHAI
燕,YAN
南海,NANHAI
宋,SONG
天市右垣,Right wall
河中,HEZHONG
河間,HEJIAN
晉,JIN
鄭,ZHENG
周,ZHOU
秦,QIN
蜀,SHU
巴,BA
梁,LIANG
楚,CHU
韓,HAN
天紀,Celestial Discipline
女床,Woman's bed
貫索,Coiled thong
七公,Seven excellencies
二十八宿, Twenty-eight mansions
角宿, Horn mansion
角,Horn
平道,Flat road
天田,Celestial farmland
周鼎,Tripod of the ZHOU
進賢,Recommending virtuous man
天門,Celestial gate
平,Judging
庫樓,Arsenal
柱,Pillars
衡,Railings
南門,Southern gate
亢宿, Neck mansion
亢,Neck
大角,Great horn
左攝提,Right conductor
右攝提,Left conductor
折威,Executions
頓頑,Trials
陽門,Gate of YANG
氐宿, Root mansion
氐,Root
亢池,Boats and lake
帝席,Mattress of the emperor
梗河,Celestial lance
招搖,Twinkling indicator
天乳,Celestial milk
天輻,Celestial spokes
陣車,Battle chariots
車騎,Chariots and cavalry
騎陣將軍,Chariot and Cavalry general
騎官,Imperial guards
房宿, Room mansion
房,Room
鉤鈐,Lock
鍵閉,Door bolt
罰,Punishment
東咸,Eastern door
西咸,Western door
日,Sun
從官,Retinue
心宿, Heart mansion
心,Heart
積卒,Group of soldiers
尾宿, Tail mansion
尾,Tail
神宮,Changing room
天江,Celestial river
傳說,FUYUE
魚,Fish
龜,Tortoise
箕宿, Winnowing-basket mansion
箕,Winnowing basket
糠,Chaff
杵,Pestle
斗宿, Dipper mansion
斗,Dipper
天龠,Celestial keyhole
天弁,Market officer
建,Establishment
天雞,Celestial cock
狗,Dog
狗國,Territory of dogs
天淵,Celestial spring
農丈人,Peasant
鱉,River turtle
牛宿, Ox mansion
牛,Ox
天桴,Celestial drumstick
河鼓,Drum at the river
左旗,Left flag
右旗,Right flag
織女,Weaving girl
漸臺,Clepsydra terrace
輦道,Imperial passageway
羅堰,Networks of dykes
天田,Celestial farmland
九坎,Nine water wells
女宿, Girl mansion
女,Girl
離珠,Pearls on ladies' wear
敗瓜,Rotten gourd
瓠瓜,Good gourd
天津,Celestial ford
奚仲,XIZHONG
扶筐,Basket for mulberry leaves
十二國,Twelve countries
周,ZHOU
秦,QIN
代,DAI
趙,ZHAO
越,YUE
齊,QI
楚,CHU
鄭,ZHENG
魏,WEI
韓,HAN
晉,JIN
燕,YAN
虛宿, Emptiness mansion
虛,Emptiness
司命,Deified judge of life
司祿,Deified judge of rank
司危,Deified judge of disaster and good fortune
司非,Deified judge of right and wrong
哭,Crying
泣,Weeping
璃瑜,Jade ornament on ladies' wear
天壘城,Celestial ramparts
敗臼,Decayed Mortar
危宿, Rooftop mansion
危,Rooftop
墳墓,Tomb
蓋屋,Roofing
虛梁,Temple
天錢,Celestial money
人,Humans
杵,Pestle
臼,Mortar
車府,Big yard for chariots
造父,ZAOFU
天鉤,Celestial hook
室宿, Encampment mansion
室,Encampment
離宮,Resting palace
螣蛇,Flying serpent
雷電,Thunder and lightning
土公吏,Official for materials supply
壘壁陣,The line of ramparts
羽林軍,Palace guard
天綱,Materials for Making Tents
北落師門,North gate of the military camp
鈇鉞,Axe
八魁,Net for catching birds
壁宿, Wall mansion
壁,Wall
天廄,Celestial stable
土公,Official for earthworks and buildings
霹靂,Thunderbolt
雲雨,Cloud and rain
鈇鑕,Sickle
奎宿, Legs mansion
奎,Legs
王良,WANGLIANG
策,Whip
附路,Auxiliary road
軍南門,Southern military gate
閣道,Flying corridor
外屏,Outer fence
天溷,Celestial pigsty
土司空,Master of constructions
婁宿, Bond mansion
婁,Bond
天大將軍,Great general of the heaven
左更,Official in charge of forest
右更,Official in charge of pasturing
天倉,Square celestial granary
天庾,Ricks of grain
胃宿, Stomach mansion
胃,Stomach
大陵,Mausoleum
積尸,Heaps of corpses
天船,Celestial boat
積水,Stored water
天廩,Celestial foodstuffs
天囷,Circular celestial granary
昴宿, Hairy Head mansion
昴,Hairy head
天阿,Celestial river
月,Moon
卷舌,Rolled tongue
天讒,Celestial slander
礪石,Whetstone
天陰,Celestial YIN force
芻蒿,Hay
天苑,Celestial meadows
畢宿, Net mansion
畢,Net
附耳,Whisper
天街,Celestial street
天高,Celestial high terrace
諸王,Feudal kings
五車,Five chariots
柱,Pillars
威池,Pool of harmony
天潢,Celestial pier
天關,Celestial gate
天節,Celestial tally
九州殊口,Interpreters of nine dialects
參旗,Banner of three stars
九斿,Imperial military flag
天園,Celestial orchard
觜宿, Turtle Beak mansion
觜,Turtle beak
司怪,Deity in charge of monsters
座旗,Seat flags
參宿, Three Stars mansion
參,Three stars
伐,Punishment
玉井,Jade well
軍井,Military well
屏,Screen
廁,Toilet
屎,Excrement
井宿, Well mansion
井,Well
鉞,Battle axe
水府,Official for irrigation
天樽,Celestial wine cup
五諸侯,Five feudal kings
北河,North river
積水,Accumulated water
積薪,Pile of firewood
水位,Water level
南河,South river
四瀆,Four channels
闕丘,Palace gate
軍市,Market for the soldiers
野雞,Wild cockerel
天狼,Celestial wolf
丈人,Grandfather
子,Son
孫,Grandson
老人,Old man
弧矢,Bow and arrow
鬼宿, Ghosts mansion
鬼,Ghosts
積尸,Cumulative corpses
爟,Beacon fire
外廚,Outer kitchen
天記,Judge to estimate the age of animals
天狗,Celestial dog
天社,Celestial earth god' s temple
柳宿, Willow mansion
柳,Willow
酒旗,Banner of wine shop
星宿, Star mansion
星,Star
天相,Celestial premier
天稷,Celestial cereals
軒轅,XUANYUAN
御女,Maids-in-waiting
內平,High judge
張宿, Extended Net mansion
張,Extended net
天廟,Celestial Temple
翼宿, Wings mansion
翼,Wings
東甌, DONGOU
軫宿, Chariot mansion
軫,Chariot
左轄,Left linchpin
右轄,Right linchpin
長沙,CHANGSHA
青丘,Green hill
軍門,Military Gate
土司空,Master of Construction
器府,House for Musical Instruments
南極星區, Southern Sky
海山,Sea and mountain
十字架,Cross
馬尾,Horse's tail
馬腹,Horse's abdomen
蜜蜂,Bee
三角形,Triangle
異雀,Exotic bird
孔雀,Peacock
波斯,Persia
蛇尾,Snake's tail
蛇腹,Snake's abdomen
蛇首,Snake's head
鳥喙,Bird's beak
鶴,Crane
火鳥,Firebird
水委,Crooked running water
附白,White patches nearby
夾白,White Patch Attached
金魚,Goldfish
海石,Sea rock
飛魚,Flying fish
南船,Southern boat
小斗,Little dipper
如上所示,双新行/n/n
分隔每个数据组,每组中的第一行代表值保持变量。
我想构建列表,以便显示上述组关系,如下所示:
三垣=c("紫微垣", "太微垣", "天市垣")
[1] "紫微垣" "太微垣" "天市垣"
`Three Enclosures`=c("Purple Forbidden Enclosure", "Supreme Palace
Enclosure", "Heavenly Market Enclosure")
[1] "Purple Forbidden Enclosure"
[2] "Supreme Palace Enclosure"
[3] "Heavenly Market Enclosure"
最好保留中国的星座和英文翻译之间的关系,可能是这样的:
> tibble(三垣, `Three Enclosures`)
# A tibble: 3 x 2
三垣 `Three Enclosures`
<chr> <chr>
1 紫微垣 Purple Forbidden Enclosure
2 太微垣 Supreme Palace Enclosure
3 天市垣 Heavenly Market Enclosure
在使用read.csv
阅读上述文件时,定义原始文件中每个组的回车信息已丢失。
> read.csv(file="chinAsterism.csv", header=F, sep=",", quote="", comment.char="", colClasses = "character")
V1
1 三垣
2 紫微垣
3 太微垣
4 天市垣
5 四象
6 青龍(東)
7 玄武(北)
8 白虎(西)
9 朱雀(南)
V2
1 Three Enclosures
2 Purple Forbidden Enclosure
3 Supreme Palace Enclosure
4 Heavenly Market Enclosure
5 Four Symbols
6 Azure Dragon (East)
7 Murky Warrior (North)
8 White Tiger (West)
9 Vermilion Bird (South)
因此,我的第一个问题是:在将非结构化或半结构化文本文件读入R时,是否有办法保留回车信息以用作进一步数据操作的指导?
我的最终目标是将上述数据集转换为如此整齐的数据框:
structure(list(abbrev = c("E1-01", "E1-02", "E1-03", "E1-04",
"E1-05", "E1-06", "E1-07", "E1-08", "E1-09", "E1-10", "E1-11",
"E2-01", "E2-02", "E2-03", "E2-04", "E2-05", "E2-06", "E2-07",
"E3-01", "E3-02", "E3-03", "E3-04", "E3-05", "E3-06", "E3-07",
"E3-08", "E3-09", "E3-10", "E3-11", "E4-01", "E4-02", "E4-03",
"E4-04", "E4-05", "E4-06", "E4-07", "E5-01", "E5-02", "E6-01",
"E6-02", "E6-03", "E6-04", "E6-05", "E7-01", "E7-02", "E7-03"
), 方位 = c("東", "東", "東", "東", "東", "東", "東",
"東", "東", "東", "東", "東", "東", "東", "東", "東",
"東", "東", "東", "東", "東", "東", "東", "東", "東",
"東", "東", "東", "東", "東", "東", "東", "東", "東",
"東", "東", "東", "東", "東", "東", "東", "東", "東",
"東", "東", "東"), 四象 = c("蒼龍", "蒼龍", "蒼龍",
"蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍",
"蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍",
"蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍",
"蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍",
"蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍",
"蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍", "蒼龍",
"蒼龍"), 宿 = c("角", "角", "角", "角", "角", "角",
"角", "角", "角", "角", "角", "亢", "亢", "亢", "亢",
"亢", "亢", "亢", "氐", "氐", "氐", "氐", "氐", "氐",
"氐", "氐", "氐", "氐", "氐", "房", "房", "房", "房",
"房", "房", "房", "心", "心", "尾", "尾", "尾", "尾",
"尾", "箕", "箕", "箕"), 星官 = c("角", "平道", "天田",
"進賢", "周鼎", "天門", "平星", "庫樓", "柱", "衡",
"南門", "亢", "大角", "折威", "左攝提", "右攝提",
"頓頑", "陽門", "氐", "天乳", "招搖", "梗河", "帝席",
"亢池", "騎官", "陣車", "車騎", "天輻", "騎陣將軍",
"房", "鍵閉", "罰", "東咸", "西咸", "日", "從官",
"心", "積卒", "尾", "龜", "天江", "傅說", "魚", "箕",
"杵", "糠"), bearing = c("East", "East", "East", "East", "East",
"East", "East", "East", "East", "East", "East", "East", "East",
"East", "East", "East", "East", "East", "East", "East", "East",
"East", "East", "East", "East", "East", "East", "East", "East",
"East", "East", "East", "East", "East", "East", "East", "East",
"East", "East", "East", "East", "East", "East", "East", "East",
"East"), symbol = c("Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon", "Azure Dragon",
"Azure Dragon", "Azure Dragon", "Azure Dragon"), mansion = c("Horn",
"Horn", "Horn", "Horn", "Horn", "Horn", "Horn", "Horn", "Horn",
"Horn", "Horn", "Neck", "Neck", "Neck", "Neck", "Neck", "Neck",
"Neck", "Root", "Root", "Root", "Root", "Root", "Root", "Root",
"Root", "Root", "Root", "Root", "Room", "Room", "Room", "Room",
"Room", "Room", "Room", "Heart", "Heart", "Tail", "Tail", "Tail",
"Tail", "Tail", "Winnowing basket", "Winnowing basket", "Winnowing basket"
), asterism = c("Horn", "Flat road", "Celestial farmland", "Tripod of the ZHOU",
"Recommending virtuous man", "Celestial gate", "Judging", "Arsenal",
"Pillars", "Railings", "Southern gate", "Neck", "Great horn",
"Right conductor", "Left conductor", "Executions", "Trials",
"Gate of YANG", "Root", "Boats and lake", "Mattress of the emperor",
"Celestial lance", "Twinkling indicator", "Celestial milk", "Celestial spokes",
"Battle chariots", "Chariots and cavalry", "Chariot and Cavalry general",
"Imperial guards", "Room", "Door bolt", "Punishment", "Eastern door",
"Western door", "Sun", "Retinue", "Heart", "Group of soldiers",
"Tail", "Tortoise", "Celestial river", "FUYUE", "Fish", "Winnowing basket",
"Chaff", "Pestle")), .Names = c("abbrev", "方位", "四象",
"宿", "星官", "bearing", "symbol", "mansion", "asterism"), row.names = c(NA,
46L), class = "data.frame")
abbrev 方位 四象 宿 星官 bearing symbol
1 E1-01 東 蒼龍 角 角 East Azure Dragon
2 E1-02 東 蒼龍 角 平道 East Azure Dragon
3 E1-03 東 蒼龍 角 天田 East Azure Dragon
4 E1-04 東 蒼龍 角 進賢 East Azure Dragon
5 E1-05 東 蒼龍 角 周鼎 East Azure Dragon
6 E1-06 東 蒼龍 角 天門 East Azure Dragon
7 E1-07 東 蒼龍 角 平星 East Azure Dragon
8 E1-08 東 蒼龍 角 庫樓 East Azure Dragon
9 E1-09 東 蒼龍 角 柱 East Azure Dragon
10 E1-10 東 蒼龍 角 衡 East Azure Dragon
11 E1-11 東 蒼龍 角 南門 East Azure Dragon
12 E2-01 東 蒼龍 亢 亢 East Azure Dragon
13 E2-02 東 蒼龍 亢 大角 East Azure Dragon
14 E2-03 東 蒼龍 亢 折威 East Azure Dragon
15 E2-04 東 蒼龍 亢 左攝提 East Azure Dragon
16 E2-05 東 蒼龍 亢 右攝提 East Azure Dragon
17 E2-06 東 蒼龍 亢 頓頑 East Azure Dragon
18 E2-07 東 蒼龍 亢 陽門 East Azure Dragon
19 E3-01 東 蒼龍 氐 氐 East Azure Dragon
20 E3-02 東 蒼龍 氐 天乳 East Azure Dragon
21 E3-03 東 蒼龍 氐 招搖 East Azure Dragon
22 E3-04 東 蒼龍 氐 梗河 East Azure Dragon
23 E3-05 東 蒼龍 氐 帝席 East Azure Dragon
24 E3-06 東 蒼龍 氐 亢池 East Azure Dragon
25 E3-07 東 蒼龍 氐 騎官 East Azure Dragon
26 E3-08 東 蒼龍 氐 陣車 East Azure Dragon
27 E3-09 東 蒼龍 氐 車騎 East Azure Dragon
28 E3-10 東 蒼龍 氐 天輻 East Azure Dragon
29 E3-11 東 蒼龍 氐 騎陣將軍 East Azure Dragon
30 E4-01 東 蒼龍 房 房 East Azure Dragon
31 E4-02 東 蒼龍 房 鍵閉 East Azure Dragon
32 E4-03 東 蒼龍 房 罰 East Azure Dragon
33 E4-04 東 蒼龍 房 東咸 East Azure Dragon
34 E4-05 東 蒼龍 房 西咸 East Azure Dragon
35 E4-06 東 蒼龍 房 日 East Azure Dragon
36 E4-07 東 蒼龍 房 從官 East Azure Dragon
37 E5-01 東 蒼龍 心 心 East Azure Dragon
38 E5-02 東 蒼龍 心 積卒 East Azure Dragon
39 E6-01 東 蒼龍 尾 尾 East Azure Dragon
40 E6-02 東 蒼龍 尾 龜 East Azure Dragon
41 E6-03 東 蒼龍 尾 天江 East Azure Dragon
42 E6-04 東 蒼龍 尾 傅說 East Azure Dragon
43 E6-05 東 蒼龍 尾 魚 East Azure Dragon
44 E7-01 東 蒼龍 箕 箕 East Azure Dragon
45 E7-02 東 蒼龍 箕 杵 East Azure Dragon
46 E7-03 東 蒼龍 箕 糠 East Azure Dragon
mansion asterism
1 Horn Horn
2 Horn Flat road
3 Horn Celestial farmland
4 Horn Tripod of the ZHOU
5 Horn Recommending virtuous man
6 Horn Celestial gate
7 Horn Judging
8 Horn Arsenal
9 Horn Pillars
10 Horn Railings
11 Horn Southern gate
12 Neck Neck
13 Neck Great horn
14 Neck Right conductor
15 Neck Left conductor
16 Neck Executions
17 Neck Trials
18 Neck Gate of YANG
19 Root Root
20 Root Boats and lake
21 Root Mattress of the emperor
22 Root Celestial lance
23 Root Twinkling indicator
24 Root Celestial milk
25 Root Celestial spokes
26 Root Battle chariots
27 Root Chariots and cavalry
28 Root Chariot and Cavalry general
29 Root Imperial guards
30 Room Room
31 Room Door bolt
32 Room Punishment
33 Room Eastern door
34 Room Western door
35 Room Sun
36 Room Retinue
37 Heart Heart
38 Heart Group of soldiers
39 Tail Tail
40 Tail Tortoise
41 Tail Celestial river
42 Tail FUYUE
43 Tail Fish
44 Winnowing basket Winnowing basket
45 Winnowing basket Chaff
46 Winnowing basket Pestle
请注意,英文和中文数据相互对应。