another option is to use relist(), e.g.,
x <- list(a=runif(10), b=runif(30), c=runif(25))
x <- as.relistable(x)
ux <- unlist(x)
ux[order(ux)[1:5]] <- -1
relist(ux)
Best,
Dimitris
jim holtman wrote:
Here is one way that might work.
x <- list(a=runif(10), b=runif(30), c=runif(25))
# unlist and then construct a factor to put them back together
x.u <- unlist(x)
x.f <- unlist(mapply(rep, names(x), sapply(x, length)))
# find the lowest 5 values and set to -1
x.u[order(x.u)[1:5]] <- -1
# put back together
split(x.u, x.f)
On Sat, Feb 21, 2009 at 11:51 PM, <mau...@alice.it> wrote:
I am experiencing some problems at working with lists at high level.
In the following "coef" contains the original DWT coefficients organized in a
list.
Thorugh applying the following two commands:
coef.abs <- lapply(unlist(coef,recursive=FALSE,use.names =TRUE),abs)
coef.abs.sorted <- sort(unlist(coef.abs),decreasing=TRUE)
I get vector "coef.abs.sorted" containing the coefficients absolute value
ordered by decreasing magnitude, whose first 10 elements I set to zero after applying an
iterative math formula (telling me how many coefficient values to spare).
My problem is setting to zero the correspondent coefficients in the original "coef" list so as to
reconstruct the signal from the depleted coefficients set, given that the above operations have erased the
list structure. I can get the labels of the coefficients that have to be zeroed ... but the names of vector
"coef.abs.sorted" elements differes from the original "coef" list elements as shown in
the following:
> names(coef.abs.sorted[1:10])
[1] "d6.d6(0)" "d5.d5(2)" "d5.d5(0)" "d4.d4(2)" "d5.d5(1)" "d4.d4(1)" "d4.d4(6)"
"d4.d4(5)" "d4.d4(3)"
[10] "d3.d3(12)"
I wonder if there exists a high level command to set to zero respectively the
coefficients in list "coef":
- Level=6, Oscillation-Number=0
- Level=5, Oscillation-Number=0,1,2
- Level=4, Oscillation-Number=1,2,3,5.6
- Level=3, Oscillation-Number=12
coef
$d1
d1(0) d1(1) d1(2) d1(3) d1(4)
d1(5) d1(6) d1(7)
1.075111e-02 -4.777441e-03 -2.775026e-03 2.011722e-03 -2.376611e-02
-1.574422e-03 -2.810372e-02 8.542393e-03
d1(8) d1(9) d1(10) d1(11) d1(12)
d1(13) d1(14) d1(15)
-1.754845e-02 -7.363856e-04 3.123922e-03 1.053743e-02 -1.014095e-02
1.059210e-02 -4.152311e-03 -7.320749e-04
d1(16) d1(17) d1(18) d1(19) d1(20)
d1(21) d1(22) d1(23)
-3.680064e-03 5.620248e-03 -2.251741e-03 -1.454674e-02 1.891275e-02
2.092009e-03 -1.286729e-02 9.037282e-03
d1(24) d1(25) d1(26) d1(27) d1(28)
d1(29) d1(30) d1(31)
-1.027137e-02 1.014230e-02 -2.175260e-03 -1.689383e-03 -2.016800e-03
3.984632e-03 -1.563781e-03 -3.801979e-03
d1(32) d1(33) d1(34) d1(35) d1(36)
d1(37) d1(38) d1(39)
6.976144e-04 1.048419e-03 -1.319865e-02 -8.368520e-04 6.618890e-03
-5.835673e-03 8.721318e-03 2.018621e-02
d1(40) d1(41) d1(42) d1(43) d1(44)
d1(45) d1(46) d1(47)
-3.329934e-03 -4.823901e-03 2.957486e-02 -2.887600e-02 2.500062e-02
-2.207839e-02 1.516034e-02 4.328945e-05
d1(48) d1(49) d1(50) d1(51) d1(52)
d1(53) d1(54) d1(55)
1.605634e-02 -2.360298e-02 7.875788e-03 -4.129065e-03 -1.014460e-02
-2.676679e-03 -9.953614e-03 -8.844977e-03
d1(56) d1(57) d1(58) d1(59)
-2.141513e-02 -7.405836e-03 -5.078857e-03 8.480675e-04
$d2
d2(0) d2(1) d2(2) d2(3) d2(4) d2(5)
d2(6) d2(7) d2(8)
0.033393680 0.015767682 -0.006008297 0.016899336 0.006661543 0.005297962
-0.005782728 -0.009358879 -0.012128449
d2(9) d2(10) d2(11) d2(12) d2(13) d2(14)
d2(15) d2(16) d2(17)
-0.014097771 0.003439004 -0.010154074 0.031203264 -0.057290615 0.004552577
0.061358997 -0.040730889 0.004064522
d2(18) d2(19) d2(20) d2(21) d2(22) d2(23)
d2(24) d2(25) d2(26)
-0.007208508 0.010426952 0.003855540 -0.011492580 0.035028591 0.029604957
-0.020069126 -0.018983905 -0.033710992
d2(27) d2(28) d2(29)
0.035848240 -0.014716622 0.008372893
$d3
d3(0) d3(1) d3(2) d3(3) d3(4) d3(5)
d3(6) d3(7) d3(8)
0.020437693 -0.023658475 0.033448175 0.009689787 0.024750901 0.040022643
0.016532575 -0.035730498 -0.048828011
d3(9) d3(10) d3(11) d3(12) d3(13) d3(14)
-0.012357469 -0.042282285 0.010908775 -0.061393069 0.058384786 -0.036842060
$d4
d4(0) d4(1) d4(2) d4(3) d4(4) d4(5)
d4(6)
0.05419644 -0.23596007 0.84412709 0.06639234 0.02718491 0.15101792
-0.18101631
$d5
d5(0) d5(1) d5(2)
2.3514158 -0.4952582 -2.5589658
$d6
d6(0)
-5.643476
coef.abs.sorted
d6.d6(0) d5.d5(2) d5.d5(0) d4.d4(2) d5.d5(1) d4.d4(1)
d4.d4(6) d4.d4(5) d4.d4(3)
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00
d3.d3(12) d2.d2(15) d3.d3(13) d2.d2(13) d4.d4(0) d3.d3(8)
d3.d3(10) d2.d2(16) d3.d3(5)
0.000000e+00 6.135900e-02 5.838479e-02 5.729061e-02 5.419644e-02 4.882801e-02
4.228228e-02 4.073089e-02 4.002264e-02
d3.d3(14) d2.d2(27) d3.d3(7) d2.d2(22) d2.d2(26) d3.d3(2)
d2.d2(0) d2.d2(12) d2.d2(23)
3.684206e-02 3.584824e-02 3.573050e-02 3.502859e-02 3.371099e-02 3.344818e-02
3.339368e-02 3.120326e-02 2.960496e-02
d1.d1(42) d1.d1(43) d1.d1(6) d4.d4(4) d1.d1(44) d3.d3(4)
d1.d1(4) d3.d3(1) d1.d1(49)
2.957486e-02 2.887600e-02 2.810372e-02 2.718491e-02 2.500062e-02 2.475090e-02
2.376611e-02 2.365848e-02 2.360298e-02
d1.d1(45) d1.d1(56) d3.d3(0) d1.d1(39) d2.d2(24) d2.d2(25)
d1.d1(20) d1.d1(8) d2.d2(3)
2.207839e-02 2.141513e-02 2.043769e-02 2.018621e-02 2.006913e-02 1.898390e-02
1.891275e-02 1.754845e-02 1.689934e-02
d3.d3(6) d1.d1(48) d2.d2(1) d1.d1(46) d2.d2(28) d1.d1(19)
d2.d2(9) d1.d1(34) d1.d1(22)
1.653258e-02 1.605634e-02 1.576768e-02 1.516034e-02 1.471662e-02 1.454674e-02
1.409777e-02 1.319865e-02 1.286729e-02
d3.d3(9) d2.d2(8) d2.d2(21) d3.d3(11) d1.d1(0) d1.d1(13)
d1.d1(11) d2.d2(19) d1.d1(24)
1.235747e-02 1.212845e-02 1.149258e-02 1.090878e-02 1.075111e-02 1.059210e-02
1.053743e-02 1.042695e-02 1.027137e-02
d2.d2(11) d1.d1(52) d1.d1(25) d1.d1(12) d1.d1(54) d3.d3(3)
d2.d2(7) d1.d1(23) d1.d1(55)
1.015407e-02 1.014460e-02 1.014230e-02 1.014095e-02 9.953614e-03 9.689787e-03
9.358879e-03 9.037282e-03 8.844977e-03
d1.d1(38) d1.d1(7) d2.d2(29) d1.d1(50) d1.d1(57) d2.d2(18)
d2.d2(4) d1.d1(36) d2.d2(2)
8.721318e-03 8.542393e-03 8.372893e-03 7.875788e-03 7.405836e-03 7.208508e-03
6.661543e-03 6.618890e-03 6.008297e-03
d1.d1(37) d2.d2(6) d1.d1(17) d2.d2(5) d1.d1(58) d1.d1(41)
d1.d1(1) d2.d2(14) d1.d1(14)
5.835673e-03 5.782728e-03 5.620248e-03 5.297962e-03 5.078857e-03 4.823901e-03
4.777441e-03 4.552577e-03 4.152311e-03
d1.d1(51) d2.d2(17) d1.d1(29) d2.d2(20) d1.d1(31) d1.d1(16)
d2.d2(10) d1.d1(40) d1.d1(10)
4.129065e-03 4.064522e-03 3.984632e-03 3.855540e-03 3.801979e-03 3.680064e-03
3.439004e-03 3.329934e-03 3.123922e-03
d1.d1(2) d1.d1(53) d1.d1(18) d1.d1(26) d1.d1(21) d1.d1(28)
d1.d1(3) d1.d1(27) d1.d1(5)
2.775026e-03 2.676679e-03 2.251741e-03 2.175260e-03 2.092009e-03 2.016800e-03
2.011722e-03 1.689383e-03 1.574422e-03
d1.d1(30) d1.d1(33) d1.d1(59) d1.d1(35) d1.d1(9) d1.d1(15)
d1.d1(32) d1.d1(47)
1.563781e-03 1.048419e-03 8.480675e-04 8.368520e-04 7.363856e-04 7.320749e-04
6.976144e-04 4.328945e-05
Thank you so much.
Maura
tutti i telefonini TIM!
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.