如果您的一条列有不均匀的行,如何在R中分开列?

发布于 2025-02-09 22:57:27 字数 491 浏览 0 评论 0原文

我有一个.csv文件,其中我有一个列,每行25-30个字符。我需要将一列分为25列,每个列在每个列中都有自己的特征(或核苷酸)。因此,我将忽略每一行的额外0-5个核苷酸。

.csv文件看起来与此相似:

序列

  • atcggtcggggggat
  • tgctggcaaa accgtcgaa
  • accgtcgaa
  • actggtaattg

我需要表看起来与此相似:

sequence sequence

  • atgct gtact
  • ggtact ggtact
  • ggtcc
  • atggtg

ggtcc 对我来说,目标是试图找到每一列的核苷酸频率,这就是为什么我需要分开列的原因。

我是R的新手,因此,任何帮助都将不胜感激!

I have a .csv file where I have one column with 25-30 characters per row. I need to separate the one column into 25 columns each with its own character (or nucleotide) inside each. Thus, I will be ignoring the extra 0-5 nucleotides in each row.

The .csv files looks similar to this:

Sequence

  • ATCGGTCGGGGGAT
  • TGCTGGCAAA
  • ACCGTCGAA
  • ACTGGTAATTG

I need the table to look similar to this:

Sequence

  • A T G C T
  • G T A C T
  • G G T C C
  • A T G T G

If this information helps: the end goal for me is trying to find the nucleotide frequencys of each column that is why I need the columns to be separated.

I am very new to R so any help would be greatly appreciated!

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

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

发布评论

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

评论(1

泅渡 2025-02-16 22:57:27

首先使用dput()提供我们可以剪切/粘贴的数据。

Sequence <- c("ATCGGTCGGGGGAT", "TGCTGGCAAA", "ACCGTCGAA", "ACTGGTAATTG")

切碎您不需要的碎片,然后将其拆分:

Sequence <- substr(Sequence, 1, 5)
Sequence <- data.frame(do.call(rbind, strsplit(Sequence, "")))
Sequence
#   X1 X2 X3 X4 X5
# 1  A  T  C  G  G
# 2  T  G  C  T  G
# 3  A  C  C  G  T
# 4  A  C  T  G  G

First use dput() to provide data that we can cut/paste.

Sequence <- c("ATCGGTCGGGGGAT", "TGCTGGCAAA", "ACCGTCGAA", "ACTGGTAATTG")

The chop off the bits you don't need and split the rest:

Sequence <- substr(Sequence, 1, 5)
Sequence <- data.frame(do.call(rbind, strsplit(Sequence, "")))
Sequence
#   X1 X2 X3 X4 X5
# 1  A  T  C  G  G
# 2  T  G  C  T  G
# 3  A  C  C  G  T
# 4  A  C  T  G  G
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文