On Sun, Nov 21, 2010 at 12:43:21PM -0800, wangwallace wrote:
here is the data frame:
a b c A B C
[1,] 1 2 3 4 5 6
[2,] 7 8 9 10 11 12
[3,] 13 14 15 16 17 18
a, b, c are type I variables
A, B, C are type II variables
each row represent the data from one
I tried it. it works out perfectly. you save my life.
--
View this message in context:
http://r.789695.n4.nabble.com/Re-how-to-apply-sample-function-to-each-row-of-a-data-frame-tp3050933p3054117.html
Sent from the R help mailing list archive at Nabble.com.
it works. I really appreciate the help! :)
--
View this message in context:
http://r.789695.n4.nabble.com/Re-how-to-apply-sample-function-to-each-row-of-a-data-frame-tp3050933p3052098.html
Sent from the R help mailing list archive at Nabble.com.
__
Hey, PS,
I revised your syntax and used it to another one of my data frames (df).
here is the data frame:
a b c A B C
[1,] 1 2 3 4 5 6
[2,] 7 8 9 10 11 12
[3,] 13 14 15 16 17 18
a, b, c are type I variables
A, B, C are type II variables
each row represent the
On Fri, Nov 19, 2010 at 07:22:57PM -0800, wangwallace wrote:
actually, what I meant is to draw two random numbers from each row
separately to create a new data frame. for example, an example output could
be:
1 3
4 5
9 8
This may be done, for example
X - matrix(1:9, ncol = 3, byrow =
this is a simple question, but I wasn't able to figure it out myself.
here is the data frame:
M P Q
1 2 3
4 5 6
7 8 9
M, P, Q each represent a variable
I want to draw 2 random sample from each row separately to create a new data
frame. how can I do it?
thanks!!
--
View this message in
Hi wangwallace,
Here are two ways of doing it. Could you please be more specific?
# data set
X - matrix(1:9, ncol = 3, byrow = TRUE)
colnames(X) - c('M', 'P', 'Q')
X
# option 1 -- two samples per row
replicate(2, {
out - t(apply(X, 1, sample))
colnames(out) - colnames(X)
list(out)
})
#
On Fri, Nov 19, 2010 at 10:34:26AM -0800, wangwallace wrote:
this is a simple question, but I wasn't able to figure it out myself.
here is the data frame:
M P Q
1 2 3
4 5 6
7 8 9
M, P, Q each represent a variable
I want to draw 2 random sample from each row separately to create
this is a simple question, but I wasn't able to figure it out myself.
here is the data frame:
M P Q
1 2 3
4 5 6
7 8 9
M, P, Q each represent a variable
I want to draw 2 random sample from each row separately to create a new
data frame. how can I do it?
thanks!!
sorry for the
9 matches
Mail list logo