# Balancing a skewed dataset in R

I am trying to classify a dataset which has 20 features and a class (target) feature. The problem is that "class-1" is found in 25% of cases while the rest 75% is "class-2" examples.

My question is : How can i under sample instances of class2 (or oversample class1 instances) in R?

I already tried to look for some answers but i would not like to use weighting.

Thank you

-

sample has a nice argument called prob. This is a vector of the same length as your x, with each element giving probability for being sampled. In my example, you would expect to get 5 in about 60% of cases.
> sample(1:5, 100, prob = c(0.1, 0.1, 0.1, 0.1, 0.6), replace = TRUE)