Filter p-values from correlation matrix w/o losing rownames an colnames

1376 views r
-2

I need to essentially accomplish this, except with a matrix of p-values. I just don't know how to retain the row and column names:

# Makeup dataframe with p-values only
val_1 = as.numeric(c("2.858941e-02", "3.605727e-02"))
val_2 = as.numeric(c("0.09654", "3.482003e-02"))
val_3 = as.numeric(c("3.517555e-02", "0.07965"))
faux.data = data.frame(val_1, val_2, val_3, row.names = c("val_4", "val_5"))

> faux.data
           val_1      val_2      val_3
val_4 0.02858941 0.09654000 0.03517555
val_5 0.03605727 0.03482003 0.07965000


# Filter, but I lose the column an row names
filtered = faux.data[faux.data < 0.05]

> filtered
[1] 0.02858941 0.03605727 0.03482003 0.03517555

answered question

Why doesn't the other answer achieve what you need? faux.data[faux.data >= 0.05] <- NA?

1 Answer

7

faux.data[faux.data < 0.05] <- "" 

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories