Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    nice one. Was going to write it ;-) Just a word of warning for the OP. In the resulting data frames the Species remains a factor with 3 levels, altough you are only considering 2 (versicolor and virginica). To drop the unused factors (in case you need it) you can use droplevels(df) assuming df is the resulting, filtered data frame. Commented Apr 25, 2017 at 11:12
  • 1
    They want to take a random sample with 80% versicolor and 20% virginica. Your approach implies that the group sizes must be equal since you just sample X% of all group entries. While it is true for the iris data set, this is often not true in real world data sets Commented Apr 25, 2017 at 11:17
  • @docendodiscimus Regardless of the underlying data set, if we want x% of a particular group, why its not true? I wanna see what I'm missing. Commented Apr 25, 2017 at 11:25
  • 1
    If I understand the OP correctly, they want a random sample of the original data where 80% of the rows of the new data set are "versicolor" and 20% are "virginica". Assume for example that the initial dataset has 50% versicolor, 10% virginica and rest other Species. Commented Apr 25, 2017 at 11:27
  • @docendodiscimus aha, thanks. that's another standpoint. But given the definition of the question (i.e., for iris data frame), its true. Commented Apr 25, 2017 at 11:33