- I would like to compare two data.
- How to select columns which has non-zero datas?.
Real data has 5000 columns.
sample1.txt
ID | VAL1 | VAL2 | VAL3 |
---|---|---|---|
ID1 | 0 | 2 | 3 |
ID2 | 0 | 2 | 3 |
ID3 | 0 | 2 | 3 |
ID,VAL1,VAL2,VAL3
ID1,0,2,3
ID2,0,2,3
ID3,0,2,3
sample2.txt
ID | VAL1 | VAL2 | VAL3 |
---|---|---|---|
ID1 | 0 | 2 | 3 |
ID2 | 0 | 2 | 3 |
ID3 | 0 | 2 | 2 |
ID,VAL1,VAL2,VAL3
ID1,0,2,3
ID2,0,2,3
ID3,0,2,2
sample1 - sample2
ID | VAL1 | VAL2 | VAL3 |
---|---|---|---|
ID1 | 0 | 0 | 0 |
ID2 | 0 | 0 | 0 |
ID3 | 0 | 0 | 1 |
select columns which has only non-zero data column like the following
ID | VAL3 |
---|---|
ID1 | 0 |
ID2 | 0 |
ID3 | 1 |
Read frame
sample1 <- read.table("sample1.txt",header=T,sep=',')
sample2 <- read.table("sample2.txt",header=T,sep=',')
comapre
result <- sample1[,2:4] - sample2[,2:4]
result
VAL1 VAL2 VAL3
1 0 0 0
2 0 0 0
3 0 0 1
How to select VAL3 columns?