由买买提看人间百态

topics

全部话题 - 话题: rbind
1 2 下页 末页 (共2页)
a****u
发帖数: 95
1
来自主题: Statistics版 - 在R中, 如何实现没有duplicate的rbind?
How about using rbind first and aggregate
x<-matrix(1:10,ncol=2,byrow=TRUE)
y<-matrix(1:20,ncol=2,byrow=TRUE)
z<-rbind(x,y)
aggregate(z,by=list(z[,1],z[,2]),FUN=tail,1)
If only duplicate for one column need to be removed, can try use match and
rbind
index<-match(x[,1],y[,1])
rbind(x[-index,],y)
t********m
发帖数: 939
2
【 以下文字转载自 DataSciences 讨论区 】
发信人: tulipdream (xiaohuaidan), 信区: DataSciences
标 题: 请教一个R问题:怎么rbind一系列data,如data1,data2,....data1000
发信站: BBS 未名空间站 (Thu Nov 13 17:35:36 2014, 美东)
有没有一个简单点的方法,类似于rbind(data1-data1000)的,求各位不吝赐教,谢谢
d********t
发帖数: 837
3
Reduce(rbind, list(data1,data2,data3,data4))
example:
Reduce(rbind, list(data.frame(x1=c(1,2,3),x2=c(2,3,4)),data.frame(x1=c(5,6,7
),x2=c(7,5,4)),data.frame(x1=c(5,4,3),x2=c(7,6,5))))
n*****3
发帖数: 1584
4
if there are patterns in the names, or you want to rbind all the datasets in
the namespace,
you can get/mget them to a list,
then Reduce(..., rbind( ), )..
t*******i
发帖数: 742
5
有个叫rbind.fill或者cbind.fill的命令
是一个人写的package
搜一下好了
k*******a
发帖数: 772
6
如果data1-data1000在一个list的话,就用do.call函数
否则可以试试
mycall = c("rbind", paste0("data", 1:1000))
mycall = lapply(mycall, as.name)
result = eval(as.call(mycall))
n*****3
发帖数: 1584
7
mget the list of dataframe by regular expression
then Reduce this list with rbind

,7
H*H
发帖数: 472
8
Reduce跟do.call都能实现,但是要是你的数据都比较大,这两个都比较慢
dplyr包的rbind_all是 do.call(rbind, list)的c++版本,
dplyr::rbind_all在数据量比较大时可以轻松提速十倍
w*******9
发帖数: 1433
9
most intuitive way (similar to kirklanda's solution):
a <- paste("data",1:1000,sep="",collapse=",")
eval(parse(text=paste(c("rbind(",a,")"),sep="")))
t********m
发帖数: 939
10
有没有一个简单点的方法,类似于rbind(data1-data1000)的,求各位不吝赐教,谢谢
o**o
发帖数: 58
11
rbindlist
或者do.call(rbind, list())
t*****w
发帖数: 254
12
来自主题: Statistics版 - 怎样来选这些dyads
answer is the following;
your final result is the following:
student teacher senior
2732 3465 1
3347 3837 1
1179 1693 1
3875 1711 1
3875 2059 1
2032 1784 1
2848 3921 1
2148 1416 1
3038 1434 1
3530 2037 1
2585 3811 1
1481 3954 1
... 阅读全帖
I*****a
发帖数: 5425
13
你这个不算是吧。
n = 1000 # training size
ntest = 1000 # test size; make this big only for illustration
id.train = 1:n
id.test = (n + 1):(n + ntest)
ratio = 0.99
n0 = round(n * ratio)
n1 = n - n0
nsimu = 100
res = NULL
for (i in 1:nsimu){
p = c(runif(n0, 0, 0.5), runif(n1, 0.5, 1), runif(ntest, 0.6, 1) )
y = sapply(p, function(x){rbinom(n = 1, size = 1, prob = x)})
x = log(p / (1 - p)) # beta is c(0, 1)
dat = data.frame(x = x, y = y)
f... 阅读全帖
z********u
发帖数: 1031
14
来自主题: Statistics版 - 新手学R的困惑。

哥 你解开了我多年的疑惑
原来是rbind的函数有问题 我说怎么我用rbind简直像死机了一样
我不是专业写R的 偶尔用用
k*******a
发帖数: 772
15
来自主题: JobHunting版 - 请教3道 brain teasers
第一题(程序算得)
#马 #可能结果
2 3
3 13
4 75
5 541
6 4683
7 47293
8 545835
附我的R code:
total<-c()
for (n in 2:8)
{
x<-(n-2):0
x<-2^x
count<-c()
for (i in 0:(2^(n-1)-1))
{
y<-floor(i/x)%%2
pos<-c(0,(1:(n-1))[y==1],n)
dif<-pos[-1]-pos[-length(pos)]
dif<-prod(factorial(dif))
dif<-factorial(n)/dif
count<-c(count,dif)
}
new<-data.frame(n=n,count=sum(count))
total<-rbind(total,new)
}
l*******r
发帖数: 3799
16
来自主题: Stock版 - Real and Theoretical DJIA
in R:
library(quantmod) # A library for stock analysis
DJIA <- c("MMM", "AA", "AXP", "T", "BAC", "BA", "CAT", "CVX", "TRV", "KO", "
DD", "XOM", "GE", "CSCO", "HPQ", "HD", "IBM", "INTC", "JNJ", "JPM", "KFT", "
MCD", "MRK", "MSFT", "PFE", "PG", "UTX", "VZ", "WMT", "DIS")
getSymbols(DJIA) # Download historical data for Dow 30 stocks
getSymbols("^DJI") # Download historical data for Dow index
x <- do.call("rbind", lapply(DJIA, function(x) get(x)[, 4])) # Extract
close price
plot
C*****H
发帖数: 7927
17
法律的问题我是不太懂。
但是编程写code run simulation的事情稍微懂一点,
看到过一篇很好的分析牌例的文章,讲述在庄家有AA而自己没有K的情况下的过手,
感谢作者,但因为不确定他本人是不是愿意被提起,所以只引用内容在此:
If we assume cards are randomly dealt, my simulation shows, given that
zhuang does have AA and doesn't have any K, the probability of having at
least one k from his partner is around .55 with 100,000 times of simulation.
Histogram shows this prob is stable.The following is my code and you're
welcome to test and give comments.
R code:
count<-NA
count1<-0
count2<-0
for(j in 1:1000... 阅读全帖
C*****H
发帖数: 7927
18
法律的问题我是不太懂。
但是编程写code run simulation的事情稍微懂一点,
看到过一篇很好的分析牌例的文章,讲述在庄家有AA而自己没有K的情况下的过手,
感谢作者,但因为不确定他本人是不是愿意被提起,所以只引用内容在此:
If we assume cards are randomly dealt, my simulation shows, given that
zhuang does have AA and doesn't have any K, the probability of having at
least one k from his partner is around .55 with 100,000 times of simulation.
Histogram shows this prob is stable.The following is my code and you're
welcome to test and give comments.
R code:
count<-NA
count1<-0
count2<-0
for(j in 1:1000... 阅读全帖
C*****H
发帖数: 7927
19
☆─────────────────────────────────────☆
Grandmaster (Garry Kasparov) 于 (Tue Sep 24 08:54:56 2013, 美东) 提到:
其实我不赞同举报作弊的做法,但我想了下,还是这么做了,回头谈谈我的想法。
证据证言推论我都有,没来得及说已经被人一通辱骂威胁。版主不喜欢我继续在这里说
话,我就此打住。如果有兴趣知道我的证据证言证人推论过程的,梦版见。
☆─────────────────────────────────────☆
ninedays (九天) 于 (Tue Sep 24 09:13:19 2013, 美东) 提到:
Evidence, please. Also better to first state the facts, i.e., what happened,
then the reason you think they were cheating. Two parts basically: 1) facts
; 2) your opinion.

☆─────────... 阅读全帖
w*m
发帖数: 1806
20
来自主题: Linux版 - How to mount?
mount舒服点,不然每次一进目录就跳到那个指定的目录,难受啊
我记得linux里是这样的,mount --rbind XX YY
solairs 下搞不定, 是不是无解?
m*****n
发帖数: 3575
21
来自主题: Programming版 - R语言,小笔记本,如何调参?
关键的问题在于循环里不能用这三个函数
c()
cbind()
rbind()
但凡你用了,慢得出奇。
解决办法是刚开始就建好纯零矩阵,然后填数。
快百倍不止。
g**********l
发帖数: 214
22
use rbind

谢谢
s******n
发帖数: 63
23
谢谢。不知道为什么用rbind时,前面的identity变量就全乱了。
a********a
发帖数: 346
24
来自主题: Statistics版 - help in R
I have a program as following,
beta1=2
beta2=8
#for (i in 1:2){
obs=2
x1=matrix(NA,obs,1)
x2=matrix(NA,obs,1)
for (g in 1:obs){
x1[g,]=runif(1,1,2)
x2[g,]=rnorm(1,1)
}
data=cbind(x1,x2)
data
#d=rbind(data[i])
#}
I run the program 2 times, and get the data like following each time,
> data
[,1] [,2]
[1,] 1.452696 0.2718456
[2,] 1.514587 1.2971293
> data
[,1] [,2]
[1,] 1.172726 -0.9674824
[2,] 1.159079 0.5483838
how can I combine these data by row, i.e. I want to get d
l*****k
发帖数: 587
25
来自主题: Statistics版 - help in R
I guess you can wrap it into a function that returns data when
called, then rbind your returned data
s*****n
发帖数: 2174
26
来自主题: Statistics版 - help in R
beta1=2
beta2=8
result <- NULL
for (i in 1:2){
obs=2
x1=matrix(NA,obs,1)
x2=matrix(NA,obs,1)
for (g in 1:obs){
x1[g,]=runif(1,1,2)
x2[g,]=rnorm(1,1)
}
data=cbind(x1,x2)
result <- rbind(result, data)
}
result
g********r
发帖数: 8017
27
来自主题: Statistics版 - R memory urgent help
而且你要用的是rbind.如果错用了cbind,可能导致部分矩阵被多次复制粘在一起。那
内存可就大了。
a********a
发帖数: 346
28
来自主题: Statistics版 - R memory urgent help
Thanks goldmember again,
Sorry, I used rbind not cbind to combine all the matrix.
Here is the situation,inside each sample, I have a loop for i in 1to 15,
In each iteration of the loop, I get estimates like the following ( here I
only list 4 columns instead of 8 columns, they are fake numbers),
sample category beta beta sigma sigma
1 1 2.0 1.2 2.0 0.8
1 2 1.0 0.8 1.2 0.1
1 2 1.5 0.7 1.3 0.8
1 3 2.0 0.4 1.5 0.2
1
s*****n
发帖数: 2174
29
来自主题: Statistics版 - R 问题
a <- c(3,6,2,5,7,9)
K <- 4
## Question 1
sum(a[a > K])
## Question 2
sum(apply(rbind(K, a), 2, max))
o****o
发帖数: 8077
30
来自主题: Statistics版 - 请教一个R:K-means的问题
use rbind to stack the two vectors:
#--------------------
> x = read.table("clipboard",sep=' ', as.is=T, header=F) #read in sample
data
> c1<-c(0.010313070, -0.02893566)
> c2<-c(0.245346732, 0.31654765)
> kmeans(x, centers=c(c1, c2))
K-means clustering with 2 clusters of sizes 3, 1
Cluster means:
V1 V2
1 0.01569253 0.1957229
2 0.54928243 -0.1534170
Clustering vector:
[1] 1 1 2 1
Within cluster sum of squares by cluster:
[1] 0.1789207 0.0000000
Available components:
[1] "clust
i********f
发帖数: 206
31
来自主题: Statistics版 - 请教一个R:K-means的问题
对的,是rbind,多谢多谢,呵呵
f***a
发帖数: 329
32
来自主题: Statistics版 - R新手求助,关于批处理运行函数
可以先把要处理的数组rbind()成一个matrix,再用apply(A,1,tt),其中tt是你需要用
的函数。注意,把tt返回的值变成list。
例子:
tt <- function(t) { result <- matrix(t,2,); list(result) }
A <- matrix(1:16,4,)
r <- apply(A,1,tt)
t**i
发帖数: 688
33
来自主题: Statistics版 - 急问如何在R里create lag variable
## suppose the third column is X
new.data = do.call("rbind",by(data, data$firm, function(dd)
{
data.frame(dd[,1:2],c(NA,dd$X[-1]),dd[,4])
}))
S******y
发帖数: 1123
34
来自主题: Statistics版 - R: what data structure is { }
I am wondering what data structure is "{ } " in R?
for example -
theta ={}
...
theta = rbind(theta, result)
Is theta a list or array?
Thanks.
t**i
发帖数: 688
35
来自主题: Statistics版 - R一问
do.call("rbind", by(...))
o****o
发帖数: 8077
36
来自主题: Statistics版 - 请教一个关于R的问题
rbind?
s******e
发帖数: 841
37
来自主题: Statistics版 - 请教一个关于R的问题
maybe it works
rbind(A,B[,match(names(A),names(B))]
D******n
发帖数: 2836
38
dat<-as.matrix(read.table('rawfile.text',sep="",col.names=1:5,fill=T));
dat[is.na(dat)]<-0;
dat<-rbind(0,dat);
result<-dat+t(dat)+diag(5);

upstream
x***x
发帖数: 3401
39
来自主题: Statistics版 - 问一个R编程问题
I have a matrix M and a array L. L contains a list of integers.
The integers are the indexes of the row numbers in the matrix M.
I want to make a new matrix N where the ith row corresponds to the L[i]th
row of the M matrix.
Is there an easy way of doing this?
I can only think of a loop with rbind() function. Any other simpler ideas or
functions?
Thanks
t**i
发帖数: 688
40
来自主题: Statistics版 - 怎样用R subset character string
do.call("rbind", strsplit(....))[,2]
t**i
发帖数: 688
41
来自主题: Statistics版 - ask R code
do.call("rbind",by(dat, dat$ID, function(dd){dd[1,]}))
R******o
发帖数: 83
42
来自主题: Statistics版 - 问 R 的 data type 问题
可以用table做n-waytable,用rbind,cbind之类灵活组合成自己想要的表,修饰一下保
存成tex 文件 用 latex 可以生成很漂亮的表。 或者存成 txt 文件,让SAS读进去再
print出来。
d*********k
发帖数: 1239
43
比如
A<-c(1,2,3,4,5)
B<-c(1,2,3)
如果直接用cbind:
> cbind(A,B)
A B
[1,] 1 1
[2,] 2 2
[3,] 3 3
[4,] 4 1
[5,] 5 2
怎么得到下面这样的形式呢?
A B
[1,] 1 1
[2,] 2 2
[3,] 3 3
[4,] 4
[5,] 5
谢谢啦啊~~
u*****3
发帖数: 796
44
cbind(A,c(B,' ',' '))
d*********k
发帖数: 1239
45
谢谢啦啊~
不过我要是有很多vector呢?要是一个一个的数element的个数的话,还是蛮麻烦的呢~
有没有什么
比较通用的方法呢?
谢谢了啊~
d******e
发帖数: 7844
d*********k
发帖数: 1239
47
我也想这用list,可是不是很熟悉
你能不能详细点?比如这个简单的例子? 谢谢啦啊
b*******g
发帖数: 513
48
Here is an example:
> a<-c(1,2,3)
> b<-c(1,2,3,4)
> c<-list(a,b)
> c
[[1]]
[1] 1 2 3
[[2]]
[1] 1 2 3 4
B**W
发帖数: 2273
49
B <- c(B, rep(NA,length(A)-length(B)))
cbind(A,B)
b*****n
发帖数: 685
50
来自主题: Statistics版 - ANOTHER r QUESTION
我FT,rbind都不会?
1 2 下页 末页 (共2页)