[R] remove column
arun
smartpink111 at yahoo.com
Sat Aug 25 08:33:51 CEST 2012
Hello,
Try this:
idx<-sapply(file,function(x) all(unique(x)==1))
file[!idx]
# V2 V3 V4 V6 V7 V8 V9
#1 0 2 2 1 5 1 1
#2 0 2 2 1 5 1 1
#3 0 2 2 2 5 2 2
#4 0 2 2 1 5 1 1
#5 0 2 2 0 5 0 2
#6 0 2 2 1 5 1 0
A.K.
----- Original Message -----
From: Kate Dresh <dreshkate at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Friday, August 24, 2012 8:11 PM
Subject: [R] remove column
*Hi all,*
I'm trying to filter a file through the columns. This file below is a
example of my data frame. My true data frame has seven hundred thousand
columns and 500 hundred lines. I need to identify and to remove all columns
that all elements equal a number 1. In this my case, columns were deleted
are number 1,5 and 10.
file <-read.table(text="
1 0 2 2 1 1 5 1 1 1
1 0 2 2 1 1 5 1 1 1
1 0 2 2 1 2 5 2 2 1
1 0 2 2 1 1 5 1 1 1
1 0 2 2 1 0 5 0 2 1
1 0 2 2 1 1 5 1 0 1
",sep="",header=FALSE)
the result after the filter will be
0 2 2 1 5 1 1
0 2 2 1 5 1 1
0 2 2 2 5 2 2
0 2 2 1 5 1 1
0 2 2 0 5 0 2
0 2 2 1 5 1 0
I used this commands idlength<-sapply(file,function(x) length(unique(x))
),
but came an error message:
caught segfault ***
address 0x4, cause 'memory not mapped'
*My question: is it possible to remove the all columns from above file
to *achieve* the desired result?*
* *
* **Thank you for help*
Kate Dresh
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list