在 R 中选择热图的列

发布于 2024-09-04 02:55:48 字数 340 浏览 4 评论 0原文

我再次需要你的帮助:)

我编写了一个 R 脚本,它根据给定的制表符分隔的 txt 或 xls 文件生成热图。目前,我在 xls 文件中手动删除了热图中不需要的所有列。 现在我想自动化它,但我不知道如何:(

所有 xls 文件中有趣的列都以相同的开头,后跟一个单独的名称:

xls-file 1: L1_tpm_xxxx L2_tpm_xxxx L3_tpm_xxxx

xls-file 2: L1_tpm_xxxx L2_tpm_xxxx L3_tpm_xxxx L4_tpm_xxxx L5_tpm_xxxx

有什么想法如何选择这些列吗?

谢谢您,Philipp

I need your help again :)

I wrote an R script, that generates a heatmap out of a given tab-seperated txt or xls file. At the moment, I delete all columns I don't want to have in the heatmap by hand in the xls file.
Now I want to automatize it, but I don't know how :(

The interesting columns all start the same in all xls files, followed by an individual name:

xls-file 1: L1_tpm_xxxx L2_tpm_xxxx L3_tpm_xxxx

xls-file 2: L1_tpm_xxxx L2_tpm_xxxx L3_tpm_xxxx L4_tpm_xxxx L5_tpm_xxxx

Any ideas how to select those columns?

Thanking you in anticipation, Philipp

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

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

发布评论

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

评论(2

莫相离 2024-09-11 02:55:49

如果您认为 Excel 工作表中的列位置是固定的,那么最简单的解决方案是仅使用列索引。例如,如果您使用 read.table 将制表符分隔的文本文件导入为 data.frame,然后决定只保留前两列,则可以执行以下操作:

data <- read.table("path_to_file.txt", header=T, sep="\t")
data <- data[,1:2]

If you think the column positions are going to be fixed across excel sheets, the simplest solution here is to just use column indices. For example, if you use read.table to import a tab-delimited text file as a data.frame, and then decide you'd prefer to only keep the first two columns, you might do something like this:

data <- read.table("path_to_file.txt", header=T, sep="\t")
data <- data[,1:2]
压抑⊿情绪 2024-09-11 02:55:48

您可以使用(如果您已在 data.frame df 中读取数据):

df <- df[,grep("^L[[:digit:]]+_tpm.*",colnames(df))]

或者您可以显式编写所需的列:

df <- df[,c("L1_tpm_xxxx","L2_tpm_xxxx","L3_tpm_xxxx")]

等等...

以下 链接非常有用;-)

You could use (if you have read your data in a data.frame df):

df <- df[,grep("^L[[:digit:]]+_tpm.*",colnames(df))]

or you can explicitly write the columns that you want:

df <- df[,c("L1_tpm_xxxx","L2_tpm_xxxx","L3_tpm_xxxx")]

etc...

The following link is quite useful;-)

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