Hi Matteo,
You could do this:
dat1<-read.table(text="
year h len fre
1994 5 10.5 2
1994 5 14.0 2
1994 5 11.5 1
1994 9 13.0 3
1994 9 11.5 1
1994 9 13.5 5
",sep="",header=TRUE)
res<-do.call(rbind,lapply(split(dat1,dat1$fre),function(x)
x[rep(row.names(x),x$fre),1:3]))
row.names(res)<
Hi,
You don't even need to split.
This could be done
dat1<-read.table(text="
year h len fre
1994 5 10.5 2
1994 5 14.0 2
1994 5 11.5 1
1994 9 13.0 3
1994 9 11.5 1
1994 9 13.5 5
",sep="",header=TRUE)
dat1[rep(row.names(dat1),dat1$fre),1:3]
# year h len
#1 1994 5 10.5
#1.1 1994
2 matches
Mail list logo