在RI在嘗試導入使用以下結構的大量文本文件:這是保存爲一個example.txt的例子:在R中,如何從分割數據的文本文件創建數據框?
Curve Name:
Curve A
Curve Values:
index Variable 1 Variable 2
[°C] [%]
0 30 100
1 40 95
2 50 90
Curve Color:
Blue
Curve Name:
Curve B
Curve Values:
index Variable 1 Variable 2
[°C] [%]
0 30 100
1 40 90
2 50 80
Curve Color:
Green
到目前爲止,我可以提取名稱和顏色
file.text <- readLines("example.txt")
curve.names <- trimws(file.text[which(regexpr('Curve Name:', file.text) > 0) + 1])
curve.colors <- trimws(file.text[which(regexpr('Curve Color:', file.text) > 0) + 1])
如何使用curve.name創建一個數據框作爲因子,其他值在下面的結構中用數字表示?
curve.name index variable.1 variable.2
Curve A 0 30 100
Curve A 1 40 95
Curve A 2 50 90
Curve B 0 30 100
Curve B 1 40 90
Curve B 2 50 80
我投了所有的答案;但是,選擇了這一個是因爲它可以處理可變長度曲線而無需額外的軟件包閱讀「Curve Values:」的累計總和適用於我所遇到的問題。 – Agriculturist