Reputation: 13
install.packages("HSAUR")
data("Forbes2000", package="HSAUR")
boxplot((log(Forbes2000$marketvalue)~Forbes2000$country))
I get the boxplot for each and every country, is there a way for me to get it for only one desired country? For example the united states (which is indexed 1 in forbes2000$country) .Here's how the code runs. . I want the highlighted part. I tried doing this :
boxplot((log(Forbes2000$marketvalue[1])~Forbes2000$country[1]))
but it's incorrect.
Upvotes: 1
Views: 34
Reputation: 33782
First, you don't need the double parentheses.
Second, try running Forbes2000$marketvalue[1]
. You'll see that it returns the first value of the column marketvalue
. So that's not what you want either.
What you need to do is select only those rows with the country of interest. One way to do that is subset
. It may also be clearer to use the formula method for boxplot
, so you can specify the data
.
boxplot(log(marketvalue) ~ country, data = subset(Forbes2000, country == "United States"))
Result:
Upvotes: 2