简体   繁体   English

删除NA值后无法查看数据框中的数据

[英]unable to view data in data frame after removing NA values

I've two data frames in time and out time with around 240 columns and 4100 rows. 我有两个数据帧,在时间上和时间上大约有240列和4100行。 There are lots of NA values in both the data frames which I need to remove and then subtract in time from out time. 在两个数据帧中都有很多NA值,我需要删除它们,然后从超时中减去时间。 I gave this command below to remove all the NA values out_time1 <- na.omit(out_time) 我在下面给出了此命令以删除所有NA值out_time1 <-na.omit(out_time)

Then when I give view(out_time) I get only head rows in my data frame. 然后,当我给出view(out_time)时,我的数据帧中只有头行。 I am unable to view any data now. 我现在无法查看任何数据。 Why is it so? 为什么会这样呢? The same thing happens with in_time data frame as well. in_time数据帧也发生相同的情况。

  1. Please help me in removing the NA values from these two data frames. 请帮助我从这两个数据帧中删除NA值。

Regards, 问候,

Pavan. 帕万

It is likely that at least 1 column for every row has an NA, resulting in no data being returned. 每行至少有1列可能具有NA,导致没有数据返回。 If you use complete.cases() you can see a row-wise NA check. 如果使用complete.cases() ,则可以看到逐行NA检查。

# Example Data
test <- diag(rep(NA,4))
test[1,1] <- 0
test
#     [,1] [,2] [,3] [,4]
#[1,]    0    0    0    0
#[2,]    0   NA    0    0
#[3,]    0    0   NA    0
#[4,]    0    0    0   NA

complete.cases(test)
#[1]  TRUE FALSE FALSE FALSE

if sum(complete.cases(test)) does not equal at least 1, then you have no rows that are absent of NA data. 如果sum(complete.cases(test))至少等于1,则您不存在不存在NA数据的行。 You should thoroughly investigate your data for NAs. 您应该彻底调查您的数据以获取NA。

You can make use of table(is.na(test)) or rowSums(is.na(test)) or colSums(is.na(test)) 您可以使用table(is.na(test))rowSums(is.na(test))colSums(is.na(test))

If you mean that View(out_time) gives you the column headers and nothing else, it is because there are no data present in the data frame, leaving just the headings. 如果您是说View(out_time)给您列标题,而没有其他内容,那是因为数据帧中没有数据,仅保留标题。

Basically, you deleted everything in the data frame because na.omit(out_time) removes any rows that have a single NA present. 基本上,您删除了数据框中的所有内容,因为na.omit(out_time)会删除所有存在单个NA行。

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

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