0
$\begingroup$

Trying to locate the names of countries in my data.frame where the most spoken language is not an official language. My columns data.frame is World. The column country.y is the name column of all the countries. Column isOfficial has data in it that is 't' or 'false' representing that the official language is 'true' or 'false'. Another column is percentage representing what percentage of a language is spoken. So far this is what I came up with.

subset(World$name.y, World$isOfficial != 't' & World$percentage > 50)
$\endgroup$
  • $\begingroup$ Can you give a snippet of the data (with say, the output of str(World) or str(World[ , c("country.y", "isOfficial", "percentage")])) to enable contributors track the class of your variables little more clearly ? $\endgroup$ – Partha D. Jan 8 '19 at 6:22
0
$\begingroup$

I would try the following R-Code for subsetting:

World[World$isOfficial != 't' & World$percentage > 50, "country.y"]

And in case isOfficial is type logical, I would try this R-code:

World[!(World$isOfficial) & World$percentage > 50, "country.y"]
| improve this answer | |
$\endgroup$
  • $\begingroup$ Here is what came out > World[World$isOfficial != 't' & World$percentage > 50, "country.y"] NULL $\endgroup$ – Chris Kehl Dec 6 '18 at 23:24
0
$\begingroup$

Is this what you're looking for?

n_var <- 24
country <- LETTERS[seq( from = 1, to = n_var )]
pcnt <- runif(min=0,max=1,n=n_var)

world_data <- data.frame(country,pcnt) %>% 
  mutate(
    is_official=ifelse(pcnt>0.5,"Y","N")
  ) %>% 
  filter(is_official=="Y")
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.