I read a csv file into R. There are options like quantity, price, size, and some others. The same product has different size and therefore different prices.
How can I separate the dataset based on size and product so I can use it to build models?
I recommend you install the package dplyr
, it has a function called filter
which you can use to extract only the rows which meet your desired condition in a data set like this
DF <- filter(DataFrame1,Size=="Large")
and lets say you want to see product = Rum
, size = Large
and price range = 10 - 40
, your command should look like:
Rums <- filter(DataFrame,product=="Rum" & size=="Large" & price>=10 & price<=40)
Hope it helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.