r - Create Vector of Factors from random labelling of rows of a data frame -


i have dataframe 110 rows pdata microarray experiment expressionset object. want create vector of factors 2 levels, randomly assigned rows (which represent samples of experiment). example, if there 110 rows corresponding 110 subjects in experiment want 55 rows set “g0” , 55 “g1”. these groups used in subsequent function. trying following wrapped within function trying modify:

# makes numeric vector of number of subjects/rows in pdata sml<-rep(0,length(colnames(eset))  # ‘populate’ sml g0 & g1  sml[sample(sml,(length(sml)/2))]<-"g0" sml[sample(sml,(length(sml)/2))]<-"g1" label <- as.factor(sml) 

how sample such g1 group completes length of sml , leaves positions assigned g0 untouched? thanks

this correct answer

eset <- matrix(na, ncol = 110, nrow = 1) <- sample(   rep(     factor(c("g0", "g1")),     ncol(eset) %/% 2   ) ) table(good) 

this bad example

bad <- sample(c("g0", "g1"), ncol(eset), replace = true) table(bad) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -