Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将特定列中的NA值转换为"&引用;R中的字段_R_Dplyr_Na - Fatal编程技术网

将特定列中的NA值转换为"&引用;R中的字段

将特定列中的NA值转换为"&引用;R中的字段,r,dplyr,na,R,Dplyr,Na,我有一个数据集df,我从Excel读入到R。出于某种原因,在读入文件时,R将所有空字段设置为NA。我该如何扭转这种局面?我希望将列中的NA值转换回空单元格 Subject Value hello NA hello NA hello NA 我想:

我有一个数据集df,我从Excel读入到R。出于某种原因,在读入文件时,R将所有空字段设置为NA。我该如何扭转这种局面?我希望将列中的NA值转换回空单元格

                      Subject     Value
                      hello       NA
                      hello       NA
                      hello       NA
我想:

                      Subject     Value
                      hello       
                      hello       
                      hello       
以下是dput:

  structure(list(Subject = structure(c(1L, 1L, 1L), .Label = "hello", class = "factor"), 
  Value = c(NA, NA, NA)), class = "data.frame", row.names = c(NA, 
 -3L))
这就是我尝试过的:

  df[is.na(df$Value)]   <- " " 

df[is.na(df$Value)]我们需要分配相同的列名

df$Value[is.na(df$Value)] <- ""
[.data.frame
(df1,is.na(df1$Value))中出错:未定义列 精选


使用
tidyverse
,我们还可以使用
replace\u na

library(dplyr)
library(tidyr)
df1 <- df1 %>%
          mutate(Value = replace_na(Value, ""))
df1
#    Subject Value
#1   hello      
#2   hello      
#3   hello     
库(dplyr)
图书馆(tidyr)
df1%
变异(值=替换(值“”))
df1
#主体价值
#你好
#2你好
#3你好

第一个很好。我将在12分钟后投票。谢谢
library(dplyr)
library(tidyr)
df1 <- df1 %>%
          mutate(Value = replace_na(Value, ""))
df1
#    Subject Value
#1   hello      
#2   hello      
#3   hello