-1

The following are the 2 initial columns of our dataset. The column on the left (with numbers) was inserter by R.

enter image description here

The following is another column in our dataset. We have calculated the mean of all values in this column.

enter image description here

We wish to compare each of the values in this last column to the mean value. (Is it higher, equal or lower than then mean value?).

To do so we used he following code:

which(databel$coverage>0.1632407, useNames=TRUE)
which(databel$coverage<0.1632407, useNames=TRUE)
which(databel$coverage==0.1632407, useNames=TRUE)

Where 0.1632407 is equal to the calculated mean of the column in the second immage.

However, this returns a list of the row number (found on the left side of the first image) rather than the place name (found on the right side of the first image)

How can we have it return the corresponding place name?

Phil
  • 7,287
  • 3
  • 36
  • 66
mcnew
  • 39
  • 5
  • We cannot copy data from an image. Add them in a reproducible format which is easier to copy. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Mar 12 '21 at 03:01

1 Answers1

0

Because which returns the indices, we can use the return value to subset the databel$Thema vector to get the names.

databel=data.frame(Thema=c("Aalst", "Aalter", "Aarschot", "Aartselaar", "Affligem", "Alken", "Alveringem", "Anderlecht"),
           coverage=c(.14,.17,.15,.13,.15,.18,.14,.16), stringsAsFactors = FALSE)

databel$Thema[which(databel$coverage>mean(databel$coverage))]
"Aalter"     "Alken"      "Anderlecht"

databel$Thema[which(databel$coverage<mean(databel$coverage))]
"Aalst"      "Aarschot"   "Aartselaar" "Affligem"   "Alveringem"

databel$Thema[which(databel$coverage==mean(databel$coverage))]
character(0)
Vons
  • 3,277
  • 2
  • 16
  • 19