r - Show me if the maximum value moved to other column -


i prepared example data let's take on it:

> dput(example1) structure(list(fr1 = c(0.2, 0, 0, 0, 0, 0), fr2 = c(0.7, 0, 0,  0, 0, 0), fr3 = c(1, 0.35, 0, 0, 0, 0), fr4 = c(0.1, 1, 0, 0,  0.5, 0), fr5 = c(0, 0.4, 0, 0, 1, 0), fr6 = c(0, 0, 0, 0, 0.3,  0), fr7 = c(0, 0, 0, 0.7, 0, 0), fr8 = c(0, 0, 0, 1, 0, 0), fr9 = c(0,  0, 0, 1, 0, 0), fr10 = c(0, 0, 0, 0.65, 0, 0.7), fr11 = c(0,  0, 0, 0.2, 0, 1)), .names = c("fr1", "fr2", "fr3", "fr4", "fr5",  "fr6", "fr7", "fr8", "fr9", "fr10", "fr11"), row.names = c("mazda rx4",  "mazda rx4 wag", "datsun 710", "hornet 4 drive", "hornet sportabout",  "valiant"), class = "data.frame")  > dput(example2) structure(list(fr1 = c(1, 0, 0, 0, 0, 0), fr2 = c(0.7, 0, 0,  0, 0, 0), fr3 = c(0.2, 0, 0, 0, 0, 0), fr4 = c(0.1, 0, 0, 0,  0.5, 0), fr5 = c(0, 0.1, 0, 0, 1, 0), fr6 = c(0, 0, 0, 0, 0.3,  0), fr7 = c(0, 0.8, 0, 0.7, 0, 0), fr8 = c(0, 1, 0, 1, 0, 0),      fr9 = c(0, 0.3, 0, 1, 0, 0), fr10 = c(0, 0, 0, 0.65, 0, 0.7     ), fr11 = c(0, 0, 0, 0.2, 0, 1)), .names = c("fr1", "fr2",  "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9", "fr10", "fr11" ), row.names = c("mazda rx4", "mazda rx4 wag", "datsun 710",  "hornet 4 drive", "hornet sportabout", "valiant"), class = "data.frame") 

so, we've got 2 data frames compare. see in cells number 0 1. number 1 maximum , has appear atleast once in each row. me important in column can find maximum , compare if it's in same column in other data frame.

example1:

    fr1 fr2  fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 mazda rx4         0.2 0.7 1.00 0.1 0.0 0.0 0.0   0   0 0.00  0.0 mazda rx4 wag     0.0 0.0 0.35 1.0 0.4 0.0 0.0   0   0 0.00  0.0 datsun 710        0.0 0.0 0.00 0.0 0.0 0.0 0.0   0   0 0.00  0.0 hornet 4 drive    0.0 0.0 0.00 0.0 0.0 0.0 0.7   1   1 0.65  0.2 hornet sportabout 0.0 0.0 0.00 0.5 1.0 0.3 0.0   0   0 0.00  0.0 valiant           0.0 0.0 0.00 0.0 0.0 0.0 0.0   0   0 0.70  1.0 

example2:

                  fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 mazda rx4           1 0.7 0.2 0.1 0.0 0.0 0.0   0 0.0 0.00  0.0 mazda rx4 wag       0 0.0 0.0 0.0 0.1 0.0 0.8   1 0.3 0.00  0.0 datsun 710          0 0.0 0.0 0.0 0.0 0.0 0.0   0 0.0 0.00  0.0 hornet 4 drive      0 0.0 0.0 0.0 0.0 0.0 0.7   1 1.0 0.65  0.2 hornet sportabout   0 0.0 0.0 0.5 1.0 0.3 0.0   0 0.0 0.00  0.0 valiant             0 0.0 0.0 0.0 0.0 0.0 0.0   0 0.0 0.70  1.0 

i made differences first , second row in example make easier work in real data there might difference in of 3000 rows. mentioned there might more 1 "maximum" in each row not more 2 - number 1 appears twice.

as output need name of row , if maximum moved (yes) or in same column (no). possible ?

to show 2 rows different in data sets:

example 1: example 1

example 2 example 2

edit:

real data:

structure(list(x10 = c(0, 0, 0, 0, 0, 0), x33.95 = c(0, 0, 0,  0, 0, 0), x58.66 = c(0, 0, 0, 0, 0, 0.164279901), x84.42 = c(0,  0, 0, 0, 0, 0), x110.21 = c(0.04925863, 0, 0, 0, 0, 0), x134.16 = c(0.4981384,  0, 0, 0, 0, 0), x164.69 = c(1, 0, 1, 0, 0, 0), x199.1 = c(0.367449159,  0, 0, 0, 1, 0), x234.35 = c(0.19587217, 0, 0, 0.96458515, 0.93848979,  0), x257.19 = c(0, 0, 0, 0.77155521, 0, 0), x361.84 = c(0, 0,  1, 0.76396661, 0, 0), x432.74 = c(0, 0, 0.81609991, 0.33773581,  0, 0), x506.34 = c(0, 0, 0.81609991, 0.1390399, 0, 0), x581.46 = c(0,  0, 0.96019504, 0.86300673, 0, 0), x651.71 = c(0, 0, 0, 0.77764596,  0, 0), x732.59 = c(0, 0, 1, 0.45950141, 0, 0), x817.56 = c(0,  0, 0, 0.14639304, 0, 0), x896.24 = c(0, 0.4013747, 0, 0.800272,  0, 0), x971.77 = c(0, 0.32393615, 0, 0.74026623, 0, 0), x1038.91 = c(0,  0.4168461, 0, 0.6808022, 0, 0), na..1 = c(0, 0.8750537, 0, 1,  0, 0), na..2 = c(0, 1, 0, 0, 0, 0), na..3 = c(0, 0.6069765, 0,  1, 0, 0), na..4 = c(0, 0.53831215, 0, 0.65073089, 0, 0)), .names = c("x10",  "x33.95", "x58.66", "x84.42", "x110.21", "x134.16", "x164.69",  "x199.1", "x234.35", "x257.19", "x361.84", "x432.74", "x506.34",  "x581.46", "x651.71", "x732.59", "x817.56", "x896.24", "x971.77",  "x1038.91", "na..1", "na..2", "na..3", "na..4"), row.names = c(na,  6l), class = "data.frame") 

new edit:

i don't it...:

> apply(alcr_ready,2,is.numeric)      na.      x10   x33.95   x58.66   x84.42  x110.21  x134.16  x164.69   x199.1  x234.35  x257.19  x361.84  x432.74     false    false    false    false    false    false    false    false    false    false    false    false    false   x506.34  x581.46  x651.71  x732.59  x817.56  x896.24  x971.77 x1038.91    na..1    na..2    na..3    na..4     false    false    false    false    false    false    false    false    false    false    false    false  

checking again:

> class(alcr_ready[2,2]) [1] "numeric" 

edit again:

'data.frame':   2188 obs. of  25 variables:  $ na.     : factor w/ 2890 levels "at1g01050","at1g01080",..: 1 2 3 4 5 6 7 10 11 12 ...  $ x10     : num  0 0 0 0 0 0 0 0 0 0 ...  $ x33.95  : num  0 0 0 0 0 0 0 0 0 0 ...  $ x58.66  : num  0 0 0 0 0 ...  $ x84.42  : num  0 0 0 0 0 0 0 0 0 0 ...  $ x110.21 : num  0.0493 0 0 0 0 ...  $ x134.16 : num  0.498 0 0 0 0 ...  $ x164.69 : num  1 0 1 0 0 0 0 0 0 0 ...  $ x199.1  : num  0.367 0 0 0 1 ...  $ x234.35 : num  0.196 0 0 0.965 0.938 ...  $ x257.19 : num  0 0 0 0.772 0 ...  $ x361.84 : num  0 0 1 0.764 0 ...  $ x432.74 : num  0 0 0.816 0.338 0 ...  $ x506.34 : num  0 0 0.816 0.139 0 ...  $ x581.46 : num  0 0 0.96 0.863 0 ...  $ x651.71 : num  0 0 0 0.778 0 ...  $ x732.59 : num  0 0 1 0.46 0 ...  $ x817.56 : num  0 0 0 0.146 0 ...  $ x896.24 : num  0 0.401 0 0.8 0 ...  $ x971.77 : num  0 0.324 0 0.74 0 ...  $ x1038.91: num  0 0.417 0 0.681 0 ...  $ na..1   : num  0 0.875 0 1 0 ...  $ na..2   : num  0 1 0 0 0 0 0 0 0 0 ...  $ na..3   : num  0 0.607 0 1 0 ...  $ na..4   : num  0 0.538 0 0.651 0 ... 

trying code:

> indx1 <- max.col(alcr_ready, 'first')==max.col(tps_ready, 'first') warning messages: 1: in max.col(alcr_ready, "first") : nas introduced coercion 2: in max.col(tps_ready, "first") : nas introduced coercion > indx2 <- max.col(alcr_ready, 'last')==max.col(tbl_tps, 'last') warning messages: 1: in max.col(alcr_ready, "last") : nas introduced coercion 2: in max.col(tbl_tps, "last") : nas introduced coercion 3: in max.col(alcr_ready, "last") == max.col(tbl_tps, "last") :   longer object length not multiple of shorter object length 

may be

 c('no', 'yes')[(max.col(example1, 'first')==max.col(example2, 'first'))+1] # [1] "no"  "no"  "yes" "yes" "yes" "yes" 

if yes denotes max moved column, should reverse

c('yes', 'no')[(max.col(example1, 'first')==max.col(example2, 'first'))+1] # [1] "yes" "yes" "no"  "no"  "no"  "no"  

if there possibility of 2 1's per row

 indx1 <- max.col(example1, 'first')==max.col(example2, 'first')  indx2 <- max.col(example1, 'last')==max.col(example2, 'last')   c('yes', 'no')[(indx1|indx2)+1] 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -