修复多个警告“未知列” [英] Fixing a multiple warning "unknown column"

查看:83
本文介绍了修复多个警告“未知列”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于所有类型的命令(例如,str(x))在安装软件包上进行更新时,我都会持续存在未知列警告,并且不知道如何调试或修复它。

I have a persistent multiple warning of "unknown column" for all types of commands (e.g., str(x) to installing updates on packages), and not sure how to debug this or fix it.

警告未知列与我重命名的tbl_df中的变量有明显的相关性,但是与tbl_df(看似无关的各种命令)例如,在包上安装更新,str(x)其中x只是一个字符向量)。

The warning "unknown column" is clearly related to a variable in a tbl_df that I renamed, but the warning comes up in all kinds of commands seemingly unrelated to the tbl_df (e.g., installing updates on a package, str(x) where x is simply a character vector).

推荐答案

我一直遇到同样的问题,虽然我不知道为什么当我们发生时,我已经能够固定下来,从而防止它发生。

I have been encountering the same problem, and although I don't know why it occurs, I have been able to pin down when it occurs, and thus prevent it from happening.

这个问题似乎是在一个基本的R数据帧中,而不是在一个字节数据帧中添加一个派生自索引的新列。以这个例子为例,在基础R数据框中添加新列( age ):

The issue seems to be with adding in a new column, derived from indexing, in a base R data frame vs. in a tibble data frame. Take this example, where you add a new column (age) to a base R data frame:

base_df <- data.frame(id = c(1:3), name = c("mary", "jill","steve"))

base_df$age[base_df$name == "mary"] <- 47

警告。但是当同样的事情完成了一个琐事,它会引发一个警告(因此,我认为导致奇怪的,看似无端的多重警告问题):

That works without returning a warning. But when the same is done with a tibble, it throws a warning (and consequently, I think causing the weird, seemingly unprovoked, multiple warning issue):

library(tibble)

tibble_df <- tibble(id = c(1:3), name = c("mary", "jill","steve"))

tibble_df$age[tibble_df$name == "mary"] <- 47

Warning message:
Unknown column 'age' 

确实有更好的方法来避免这种情况,但是我发现首先创建一个 NA的向量的工作:

There are surely better ways of avoiding this, but I have found that first creating a vector of NAs does the job:

tibble_df$age <- NA

tibble_df$age[tibble_df$name == "mary"] <- 47

这篇关于修复多个警告“未知列”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆