由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - R question
相关主题
为什么biglm能处理data sets larger than memory?【R求问】关于vector赋值
求用R做bootstrap的example script【R】保留matrix中某些值
突然对直线拟合的R不明白起来了SAS code question, special two do loop
两个有关于R的小问题?how to get a length of a vector in SAS/IML
请教一个概率题的思路请问下SAS执行中有什么单步执行之类的命令吗? 为什么我的proc iml里设置的参数t无论怎么改,结果都不变呢?
Urgent R Question这个R程序能帮改进一下吗?
R 画图问题求教请教高人如何用一个表格的列去替换另一个表格的列?
a R loop question请教:关于covariance matrix
相关话题的讨论汇总
话题: experiment话题: say话题: nrow话题: combn话题: question
进入Statistics版参与讨论
1 (共1页)
g**r
发帖数: 425
1
If I have the result x=combn(3,3); and y=comb(5,4).
(x=1,2,3; y={1 2 3 4; 1 2 3 5; 1 2 4 5; 1 3 4 5; 2 3 4 5}
How can I remove those columns from y that the first 3 elements=X?
newy={1 2 4 5; 1 3 4 5; 2 3 4 5}
Any help is greatly appreciated...
(Bkgroud:
I have an experiment, and the total number of people in this experiment can
reach n, say 10.
Each result will be just Ber, say with p=0.2.
How ever, if I observe certain results, I will not continue the experiment.
Say if I see 3 out of 3 sucess
y****2
发帖数: 34
2
y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
x <- c(1,2,3)
temp <- matrix(match(y, x), nrow=4)
n <- ncol(temp)
index <- rep(0,n)
for(i in 1:n){
comp <- temp[1:length(x),i]== 1:length(x)
index[i] <- i*(sum(comp, na.rm=T)==length(x))
}
ynew <- y[,-index]
You may try this one. I am thinking that the for loop could be replaced by a
more efficient code. (You know, for loop might be slow for large data set)
q**j
发帖数: 10612
3
R里面能不能直接比较vector?
x = c(1,2,3)
y = c(4,5,6)
> x == y
[1] FALSE FALSE FALSE
总是一个element的比。
s*****n
发帖数: 2174
4
y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
x <- c(1,2,3)
y[, apply(y[1:3,], 2, function(t) all(t==x))]

can
.

【在 g**r 的大作中提到】
: If I have the result x=combn(3,3); and y=comb(5,4).
: (x=1,2,3; y={1 2 3 4; 1 2 3 5; 1 2 4 5; 1 3 4 5; 2 3 4 5}
: How can I remove those columns from y that the first 3 elements=X?
: newy={1 2 4 5; 1 3 4 5; 2 3 4 5}
: Any help is greatly appreciated...
: (Bkgroud:
: I have an experiment, and the total number of people in this experiment can
: reach n, say 10.
: Each result will be just Ber, say with p=0.2.
: How ever, if I observe certain results, I will not continue the experiment.

y****2
发帖数: 34
5
Yeah, that's exactly what I want. :-) "all" function is nice.

【在 s*****n 的大作中提到】
: y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
: x <- c(1,2,3)
: y[, apply(y[1:3,], 2, function(t) all(t==x))]
:
: can
: .

g**r
发帖数: 425
6
Thaks; following ur lead, i searched a few more fuctions and the following
seems to work:
x3=combn(3,3)
tx4=combn(5,4)
ttx4=tx4[1:nrow(x3),]
k=0
for (i in 1:ncol(ttx4))
if (sum(apply(y,2,setequal,x=ttx4[,i]))>0 ) k=c(k,-1*i)
x4=tx4[,k]

【在 y****2 的大作中提到】
: y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
: x <- c(1,2,3)
: temp <- matrix(match(y, x), nrow=4)
: n <- ncol(temp)
: index <- rep(0,n)
: for(i in 1:n){
: comp <- temp[1:length(x),i]== 1:length(x)
: index[i] <- i*(sum(comp, na.rm=T)==length(x))
: }
: ynew <- y[,-index]

g**r
发帖数: 425
7
nice, thx

【在 s*****n 的大作中提到】
: y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
: x <- c(1,2,3)
: y[, apply(y[1:3,], 2, function(t) all(t==x))]
:
: can
: .

q**j
发帖数: 10612
8
thanks. just to make sure:
the third argument of apply() is an inline function definition right?
never know that *apply functions can be used this way.

【在 s*****n 的大作中提到】
: y <- matrix(c(1,2,3,4,1,3,2,5,1,2,3,5,2,3,4,1), nrow=4)
: x <- c(1,2,3)
: y[, apply(y[1:3,], 2, function(t) all(t==x))]
:
: can
: .

q**j
发帖数: 10612
9
and if this works, then my previous question about selecting variables in
one data frame but not in another data frame can be solved as well.
1 (共1页)
进入Statistics版参与讨论
相关主题
请教:关于covariance matrix请教一个概率题的思路
关于R的一个编程问题,怎么存储数据在一个向量?Urgent R Question
请教R Code, 多谢!R 画图问题求教
求问一个R apply 函数的问题a R loop question
为什么biglm能处理data sets larger than memory?【R求问】关于vector赋值
求用R做bootstrap的example script【R】保留matrix中某些值
突然对直线拟合的R不明白起来了SAS code question, special two do loop
两个有关于R的小问题?how to get a length of a vector in SAS/IML
相关话题的讨论汇总
话题: experiment话题: say话题: nrow话题: combn话题: question