[R] generate ordered categorical variable in R

David L Carlson dcarlson at tamu.edu
Wed Sep 16 19:33:22 CEST 2015


There is a version of sample especially for integers:

> Q1 <- matrix(sample.int(4, 200, replace=TRUE), 200)
> str(Q1)
 int [1:200, 1] 1 4 4 2 3 3 4 4 2 3 ...

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of thanoon younis
Sent: Wednesday, September 16, 2015 12:11 PM
To: r-help at r-project.org
Subject: [R] generate ordered categorical variable in R

Dear R- users

I want to generate ordered categorical variable vector with 200x1 dimension
and from 1 to 4 categories and i tried with this code

Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results with
decimals like 1.244, 2.342,4,321 and so on ... My question how can i
generate a vector and also a matrix with orered categorical variables and
without decimals just 1,2,3 ,4 ,1,2,3,4, ....

Many thanks in advance





-- 
Thanoon Y. Thanoon
PhD Candidate
Department of Mathematical Sciences
Faculty of Science
University Technology Malaysia, UTM
E.Mail: Thanoon.younis80 at gmail.com
E.Mail: dawn_prayer80 at yahoo.com
Facebook:Thanoon Younis AL-Shakerchy
Twitter: Thanoon Alshakerchy
H.P:00601127550205

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list