Replacing column one values in R
0
0
Entering edit mode
8.3 years ago
waqasnayab ▴ 250

Hi,

I want to replace column one values with genome string.

I did the following:

cvrge <- read.table("genome_cvrge_hist_nochr.txt")
> head (cvrge)
  V1 V2       V3        V4        V5
1  1  0 36163905 249250621 0.1450910
2  1  1  7607795 249250621 0.0305227
3  1  2  8370524 249250621 0.0335828
4  1  3  9328821 249250621 0.0374275
5  1  4 10150841 249250621 0.0407254
6  1  5 10750946 249250621 0.0431331
> gcov = cvrge[cvrge[,1] == 'genome',]
> gcov
[1] V1 V2 V3 V4 V5
<0 rows> (or 0-length row.names)

I am expecting the following output:

> head (cvrge)
      V1 V2       V3        V4        V5
    1  genome  0 36163905 249250621 0.1450910
    2  genome  1  7607795 249250621 0.0305227
    3  genome  2  8370524 249250621 0.0335828
    4  genome  3  9328821 249250621 0.0374275
    5  genome  4 10150841 249250621 0.0407254
    6  genome  5 10750946 249250621 0.0431331

where I am wrong,

Thanks,

Waqas.

R next-gen alignment • 1.9k views
ADD COMMENT
2
Entering edit mode
... cvrge[,1] == 'genome'... tests for equality. It doesn't update the values. You need to use


   cvrge[, 1] <- 'genome'
ADD REPLY
1
Entering edit mode

As it's a data frame, this should also work:

cvrge$V1 <- "genome"
ADD REPLY

Login before adding your answer.

Traffic: 1303 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6