0

I am trying to plot a graph that displays the cost of apps but only if they cost more than 0 (aren't free) I have tried the filter function but got nowhere.

if (df$Price > 0){
  barplot(table(df$Price))
}

I have also tried an if statement but it gives me a warning message saying:

In if (df$Price == test) { :
  the condition has length > 1 and only the first element will be used

I am new to R studio so any help would be appreciated

camille
  • 16,432
  • 18
  • 38
  • 60
xdmojojojodx
  • 23
  • 3
  • 8
  • 5
    Use `barplot(table(df$Price[df$Price>0]))`. You need to subset the vector. `df$Price` has many prices, some more than 0, some not. You can't just have one `if` statement deal with all the values differently. `if` is not vectorized in R. – MrFlick Oct 31 '19 at 20:49
  • @MrFlick ```In Ops.factor(df$Price, 0) : ‘>’ not meaningful for factors``` Getting this warning message and the graph is now displaying no values at all? – xdmojojojodx Oct 31 '19 at 20:52
  • 1
    Well, sounds like your Price column is not numeric. Changes are you didn't import your data correctly or there are weird values in your Price column. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Oct 31 '19 at 20:53
  • [Related](https://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-integer-numeric-without-loss-of-information) to the error you're now getting. – Rui Barradas Oct 31 '19 at 20:58

0 Answers0