简体   繁体   English

从数据框中的两列中删除 NA 上移

[英]Removing NAs from two columns in data frame a shift up

I have this data frame我有这个数据框

                               atac.v1.pbmc.5k.possorted.bam.bam possorted.bam.bam
chr1.9941.10736                                 NA                NA
                                             13196              4348
chr1.10918.11476                                NA                NA
                                              2624               658
chr1.20874.21591                                NA                NA
                                               652               343

and I would like to remove the NAs and get this:我想删除 NAs 并得到这个:

                               atac.v1.pbmc.5k.possorted.bam.bam possorted.bam.bam
chr1.9941.10736                              13196              4348                 
chr1.10918.11476                             2624               658                  
chr1.20874.21591                             652                343 
                                             

There are many questions about removing NAs, but I couldn't manage to use any of them to do this.关于删除 NA 有很多问题,但我无法使用它们中的任何一个来做到这一点。 I tried remove NAs and various code to remove white spaces, but wasn't able to.我尝试删除 NA 和各种代码来删除空格,但没能成功。

For R a similar question was already asked here .对于 R, 这里已经提出了类似的问题。

Thus when you want to solve it in R you can eg.因此,当您想在 R 中解决它时,您可以例如。 use the following:使用以下内容:

df = data.frame('name'=c('a',NA,'b',NA), 'val'=c(NaN, 1, NaN, 5))
library(dplyr)
na.omit(transform(df, name = lag(name)))

The df is only given to have a minimal running program. df 只给出了一个最小的运行程序。

Hi @RicS and @Robert Wilson, after I put dput(df) i get this嗨@RicS 和@Robert Wilson,在我输入 dput(df) 之后,我得到了这个

"", "s37d5.35353959.35354523", "", "s37d5.35354792.35354991", 
"", "s37d5.35364108.35364390", "", "s37d5.35365154.35365375", 
"", "s37d5.35371939.35372823", "", "s37d5.35373959.35374177", 
"", "s37d5.35382938.35383151", "", "s37d5.35391117.35391934", 
"", "s37d5.35391998.35392218", "", "s37d5.35411836.35412109", 
"", "s37d5.35427424.35427818", "", "s37d5.35431087.35431415", 
"", "s37d5.35431545.35431772", "", "s37d5.35449122.35449455", 
"", "s37d5.35449665.35450121", "", "s37d5.35451782.35451987", 
"", "s37d5.35453892.35454283", ""), c("atac.v1.pbmc.5k.possorted.bam.bam", 
"possorted.bam.bam")))

I just copied and pasted some of it.我只是复制并粘贴了一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM