使用R或Excel将TXT文件导入和转换为CSV

发布于 2025-02-07 16:00:36 字数 1828 浏览 3 评论 0原文

除了非常基本的转换外,我几乎没有转换TXT数据的经验,而且我一直在尝试使用Excel Power查询和整理R中的某个小时

。关于三个植被调查图的数据,尽管我的实际数据超过1600个图:

Plot 1
CVS: class 49
ELL: No data for 2 species: Betula seedling/sp; Quercus seedling/sp
ELL: Light 5.6; Wetness 5.5; pH 3.9; Fertility 4.2
CSR: 2 species with no data: Betula seedling/sp; Pinus sylvestris
CSR: C: 2.89  S: 2.35  R: 2.33
BIO: 2 species with no data: Betula seedling/sp; Quercus seedling/sp
BIO: Eurasian Boreal-montane 14%
BIO: Eurosiberian Boreo-temperate 14%
BIO: Oceanic Temperate 14%
BIO: European Temperate 14%
BIO: Eurosiberian Temperate 14%
BIO: Circumpolar Temperate 14%
BIO: European Southern-temperate 14%

Plot 2
CVS: class 42
ELL: No data for 2 species: Betula seedling/sp; Quercus seedling/sp
ELL: Light 5.2; Wetness 5.2; pH 4.9; Fertility 5.4
CSR: 2 species with no data: Betula seedling/sp; Tilia [spp]
CSR: C: 2.36  S: 2.79  R: 2.75
BIO: 3 species with no data: Betula seedling/sp; Quercus seedling/sp; Tilia [spp]
BIO: Oceanic Temperate 25%
BIO: European Temperate 50%
BIO: Eurosiberian Temperate 25%

Plot 3
CVS: class 42
ELL: No data for 1 species: Quercus seedling/sp
ELL: Light 4.9; Wetness 5.2; pH 5.9; Fertility 5.5
CSR: C: 2.74  S: 3.25  R: 2.49
BIO: 2 species with no data: Acer pseudoplatanus; Quercus seedling/sp
BIO: Circumpolar Wide-boreal 11%
BIO: Circumpolar Boreo-temperate 11%
BIO: Eurosiberian Wide-temperate 11%
BIO: European Temperate 22%
BIO: Eurosiberian Temperate 11%
BIO: Circumpolar Temperate 11%
BIO: European Southern-temperate 22%

我实际上不需要保留太多数据,但我需要保留和转换前两行中的信息,也需要行5/6(CSR) )我需要的是以下格式的表:

PLOT    CVS      C      S      R
 1       49      2.89   2.35   2.33
 2       42      2.36   2.79   2.75
 3       42      2.74   3.25   2.49  

这甚至可以从现有的TXT格式做到这一点吗?令人遗憾的是,我对这个主题毫无头绪,似乎没有任何谷歌搜索能有所帮助。所有思想都非常感谢。

I have very little experience with transforming txt data except for very basic transformations and I have been trying for about an hour now to get somewhere using Excel power query and Tidyverse in R.

I have a txt file in the following format, the below example shows data on three vegetation survey plots, though my actual data is over 1600 plots:

Plot 1
CVS: class 49
ELL: No data for 2 species: Betula seedling/sp; Quercus seedling/sp
ELL: Light 5.6; Wetness 5.5; pH 3.9; Fertility 4.2
CSR: 2 species with no data: Betula seedling/sp; Pinus sylvestris
CSR: C: 2.89  S: 2.35  R: 2.33
BIO: 2 species with no data: Betula seedling/sp; Quercus seedling/sp
BIO: Eurasian Boreal-montane 14%
BIO: Eurosiberian Boreo-temperate 14%
BIO: Oceanic Temperate 14%
BIO: European Temperate 14%
BIO: Eurosiberian Temperate 14%
BIO: Circumpolar Temperate 14%
BIO: European Southern-temperate 14%

Plot 2
CVS: class 42
ELL: No data for 2 species: Betula seedling/sp; Quercus seedling/sp
ELL: Light 5.2; Wetness 5.2; pH 4.9; Fertility 5.4
CSR: 2 species with no data: Betula seedling/sp; Tilia [spp]
CSR: C: 2.36  S: 2.79  R: 2.75
BIO: 3 species with no data: Betula seedling/sp; Quercus seedling/sp; Tilia [spp]
BIO: Oceanic Temperate 25%
BIO: European Temperate 50%
BIO: Eurosiberian Temperate 25%

Plot 3
CVS: class 42
ELL: No data for 1 species: Quercus seedling/sp
ELL: Light 4.9; Wetness 5.2; pH 5.9; Fertility 5.5
CSR: C: 2.74  S: 3.25  R: 2.49
BIO: 2 species with no data: Acer pseudoplatanus; Quercus seedling/sp
BIO: Circumpolar Wide-boreal 11%
BIO: Circumpolar Boreo-temperate 11%
BIO: Eurosiberian Wide-temperate 11%
BIO: European Temperate 22%
BIO: Eurosiberian Temperate 11%
BIO: Circumpolar Temperate 11%
BIO: European Southern-temperate 22%

I actually don't need to keep much of this data, I need to retain and transform the information in the first two rows and also row 5/6 (CSR) what I need is a table in the following format:

PLOT    CVS      C      S      R
 1       49      2.89   2.35   2.33
 2       42      2.36   2.79   2.75
 3       42      2.74   3.25   2.49  

Is this even possible to do from the existing txt format? I am sadly clueless on this subject and no amount of googling seems to help. All thoughts much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尸血腥色 2025-02-14 16:00:37

可以将“绘图n”行始终处于第一个位置,cvs:class nn”行第二个位置 和csr:c:nn .. 。 ETC。” 总是处于第六位

因为在这种情况下,我认为我有一些Excel公式可以为您提供此结果:

我的结果

公式是这些(B6单元格中的启动):

B列:
=清洁(if(iSnumber)(搜索(“ plot”; a1)); mid(a1; 6; 6; 10);“”))

c列:
=清洁(如果(iSnumber)(搜索(“ cvs:class”; a2)); mid(a2; 12; 12; 10);“”))

d列:
=清洁(如果(iSnumber)(搜索(“ CSR:C:”; A2)); MID(A6; 9; 5);“”))

E列:
=清洁(如果(iSnumber)(搜索(“ CSR:C:”; A2)); MID(A6; 18; 5);“”))

F列:
(搜索(“ csr:c:”; a2)); mid(a6; 27; 5)

=干净(if(iSnumber ) ,Excel中的数据并不能完美显示。因此,我的最初问题。

我希望它对您有帮助。

It is possible to put the "Plot n" row always in first position, the CVS: class nn" row in second position, and the CSR: C: nn... etc." ALWAYS in sixth position?

Because in that case I think I have some Excel formulas that can help you with this result:

My result

The formula are these (startin in the B6 cell):

B column:
=CLEAN(IF(ISNUMBER(SEARCH("Plot";A1));MID(A1;6;10);""))

C column:
=CLEAN(IF(ISNUMBER(SEARCH("CVS: class ";A2));MID(A2;12;10);""))

D column:
=CLEAN(IF(ISNUMBER(SEARCH("CSR: C: ";A2));MID(A6;9;5);""))

E column:
=CLEAN(IF(ISNUMBER(SEARCH("CSR: C: ";A2));MID(A6;18;5);""))

F column:
=CLEAN(IF(ISNUMBER(SEARCH("CSR: C: ";A2));MID(A6;27;5);""))

As you can see in the image, when there is one less line in the txt, the data in the excel does not display perfectly. Hence my initial question.

I hope it helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文