问题描述
所以它有一个csv我正在读入一个R数据帧,它看起来像这样
clientx,clienty,screenx ,screeny
481,855,481,847
481,784,481,847
481,784,481,847
879,292,879,355
第一行当然是标题。所以我们有4列数字数据,范围从1到4位数。除了-1表示缺失值,集合中没有负数。
我想删除在4列中的任何一行包含-1的每一行。
提前感谢帮助
你最有效的方式是使用 > read.csv()
将所有 -1
值编码为 NA
,然后删除不完整的情况。
步骤1:设置 步骤2:现在使用 So it got a csv I'm reading into an R dataframe, it looks like this First line is of course the header. So we have 4 columns with numeric data in it, ranging from 1 to 4 digits. There are no negative numbers in the set except -1 which marks a missing value.I want to remove every row that contains a -1 in any of the 4 columns. Thanks in advance for the help Your most efficient way will be to use the Step 1: set Step 2: Now use 这篇关于R删除包含一定值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! na.strings = $
code code code code code code code code $ c> x< - read.csv(text =
clientx,clienty,screenx,screeny
481,855,481,847
481,784,481,847
481,784,481,847
-1,292,879,355,标题= TRUE,na.strings = -1)
x
clientx clienty screenx screeny
1 481 855 481 847
2 481 784 481 847
3 481 784 481 847
4 NA 292 879 355
complete.cases
或 na.omit
:
x [complete.cases(x ),]
pre>
clientx clienty screenx screeny
1 481 855 481 847
2 481 784 481 847
3 481 784 481 847
na.omit( x)
clientx clienty screenx screeny
1 481 855 481 847
2 481 784 481 847
3 481 784 481 847
clientx,clienty,screenx,screeny
481,855,481,847
481,784,481,847
481,784,481,847
879,292,879,355
na.strings
argument of read.csv()
to code all -1
values as NA
, then to drop incomplete cases.na.strings=-1
in read.csv()
:x <- read.csv(text="
clientx,clienty,screenx,screeny
481,855,481,847
481,784,481,847
481,784,481,847
-1,292,879,355", header=TRUE, na.strings=-1)
x
clientx clienty screenx screeny
1 481 855 481 847
2 481 784 481 847
3 481 784 481 847
4 NA 292 879 355
complete.cases
or na.omit
:x[complete.cases(x), ]
clientx clienty screenx screeny
1 481 855 481 847
2 481 784 481 847
3 481 784 481 847
na.omit(x)
clientx clienty screenx screeny
1 481 855 481 847
2 481 784 481 847
3 481 784 481 847