将值保持在数据框中= Na(化学钠) [英] Keep values in data frame= Na (sodium in chemistry) as is
本文介绍了将值保持在数据框中= Na(化学钠)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Subject Code Test Value Units Flag
1 NA NA 147 mmol/L
2 NA/K NA/K 10.5 RATIO
3 K K 4.7 mmol/L
4 CK CK 235 UL
...
清洁后理想的df
Subject Code Test Value Units Flag
1 NA Sodium 147 mmol/L NA
2 NA/K Sodium Potassium 10.5 RATIO NA
3 K Potassium 4.7 mmol/L NA
4 CK Creatine Kinase 235 UL NA
...
我尝试过的
df <- read.csv(file="clinchemistry.csv", header = TRUE, sep=",", stringsAsFactors = FALSE)
df$df[df8$Test == "NA"] <- "Sodium"
df$df[df8$Code == "NA"] <- "Sodium"
和
df[is.na(lb$Code)]<-"Sodium"
lb[is.na(lb$Code)]<-"Sodium"
结果:
所有钠值消失或出现错误:
All the sodium values disappear or get an error:
[<-.data.frame
中的错误(*tmp*
,is.na(lb $ Tesst),value ="Sodium") :列的下标重复
Error in
[<-.data.frame
(*tmp*
, is.na(lb$Tesst), value = "Sodium") : duplicate subscripts for columns
有人会指导我吗?
推荐答案
使用na.strings=""
df <- read.csv(file="clinchemistry.csv",
na.strings="", stringsAsFactors = FALSE)
(忽略设置为默认值的参数)
(omitting arguments that are set to their default values)
这篇关于将值保持在数据框中= Na(化学钠)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文