Hi Marta,
If your first dataset "field2" is greater than the number of rows for a
particular "field1" in second dataset, this error could happen.
e.g. using modified dat1:
dat1 <- structure(list(field1 = 1:3, field2 = c(3L, 20L, 4L)), .Names =
c("field1",
"field2"), class = "data.frame", row.n
Hi Marta,
If you need random selection, you could use:
do.call(rbind,lapply(split(dat2,dat2$field1),function(x)
x[sample(1:nrow(x),dat1$field2[!is.na(match(dat1$field1,x$field1))],replace=FALSE),]))
A.K.
On Tuesday, April 22, 2014 1:45 PM, arun wrote:
Hi Marta,
It's not clear whether you w
Hi Marta,
It's not clear whether you wanted to select the first "n" rows specified by
field2 in the first dataset or just random rows.
##using a modified example if my guess is correct
dat1 <- structure(list(field1 = 1:3, field2 = c(3L, 6L, 4L)), .Names =
c("field1",
"field2"), class = "data.
Tobeña
Sent: Monday, April 21, 2014 10:08 AM
To: r-help@r-project.org
Subject: [R] Hi , Is it possible select a different number of
rows by each group with R
Hi , Is it possible select a different number of rows by each
group with R
I must to select different number (specific quantity in
Hi , Is it possible select a different number of rows by each group with R
I must to select different number (specific quantity in field2:Table1) of rows
in each group(field1:Table2). I have these 2
tables:Table1Table2field1field2field1field3field4field51310.375SpRm12610.416667SpRm23910.45833
5 matches
Mail list logo