作者wlsherica (Mon_tresor)
看板Statistics
标题[问题] R 产生新变项
时间Wed Apr 15 11:25:59 2009
有一个R程式的问题想请教大家,
现在样本数为100, 变项为height, 我想随机抽50个人当作控制组, 剩下50人当作对照组.
我现在是用sample写,可是不知道怎麽指定剩下的50人当作第二组...
目前想法是抽出50人之後, 用原本的100人去减, 可是会有0出现....@@
另外想问说在R里面, 怎麽创造一个新变项呢....
还是说有更好的方法???
查了很久没得到答案, 因此想请教各位~! 请大家指点~
谢谢大家~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.183.69
1F:→ cravingtrue:令d为资料变数,control=sample(d,50) 04/15 12:35
2F:→ cravingtrue:d[control],d[-control],这样可以分出两群 04/15 12:35
3F:→ wlsherica:喔我失败了,她无法减去,我在试试看 04/17 13:00
4F:→ bmka:d 应该设为row indicator. eg: d <- 1:N, where N is the 04/17 19:56
5F:→ bmka:number of rows 04/17 19:56
6F:→ bmka:indx <- sample (1:100, 50); dat1<- dat[ indx, ] 04/17 19:58
7F:→ bmka:dat0 <- dat[-indx,] 04/17 19:59