Re: [R] Question on apply() with more information...

From: <markleeds_at_verizon.net>
Date: Mon 18 Sep 2006 - 17:12:13 GMT


>From: =?ISO646-US?Q?Gunther_H=3Fning?= <gunther.hoening@ukmainz.de>
>Date: 2006/09/18 Mon AM 06:26:25 CDT
>To: 'Petr Pikal' <petr.pikal@precheza.cz>
>Cc: r-help@stat.math.ethz.ch
>Subject: Re: [R] Question on apply() with more information...

I think you want something like below but it probably needs some fixing up because i don't recall the syntax exactly.

predictdata<-lapply(i=1:length(Smoothlist),function predict (smthlist[[i]],xarry[i,])smthlist= SmoothList,xarry=Xarry)

>Hi,
>
>I tried both ideas, but it isn't that what I'm looking for.
>I want to avoid for loop, because the matrix is of big size(1200*1200
>entries)
>
>With a loop I would do:
>
>for ( i in seq(along = SmoothList))
>{
> Xarry[i,] <- predict(SmoothList[[i]],Xarry[i,])$y
>}
>
>Actually I want to do more than just to predict a value, but it isn't
>important for the initial question...
>
>Gunther
>
>-----Ursprüngliche Nachricht-----
>Von: Petr Pikal [mailto:petr.pikal@precheza.cz]
>Gesendet: Montag, 18. September 2006 11:44
>An: Gunther Höning
>Cc: r-help@stat.math.ethz.ch
>Betreff: Re: AW: [R] Question on apply() with more information...
>
>Hi
>
>If I am correct apply do not choose from SmoothList as you expected.
>Instead probably
>
>lapply(SmoothList, predict,Xarray)
>or
>mapply(predict,SmoothList, Xarray)
>
>can give you probably what you want.
>
>HTH
>Petr
>
>
>On 18 Sep 2006 at 9:26, Gunther Höning wrote:
>
>From: Gunther Höning <gunther.hoening@ukmainz.de>
>To: "'Petr Pikal'" <petr.pikal@precheza.cz>,
> <r-help@stat.math.ethz.ch>
>Subject: AW: [R] Question on apply() with more information...
>Date sent: Mon, 18 Sep 2006 09:26:01 +0200
>
>> Ok.
>> I tried this too, but it still doesn't work.
>> Here some more information to try out, but just an excerpt of Xarray
>>
>> x <- c(0.11,0.25,0.45,0.65,0.80,0.95,1)
>> Y <-
>> matrix(c(15,83,57,111,150,168,175,37,207,142,277,375,420,437),nrow=2)
>>
>> sm <- function(y,x){smooth.spline(x,y)} SmoothList <- apply(Y,1,sm,x)
>> NewValues <- function(x,LIST){predict(LIST,x)} Xarray <-
>> matrix(c(0.15,0.56,0.66,0.45,0.19,0.17,0.99,0.56,0.77,0.41,0.11,0.63,0
>> .42,0. 43),nrow=2)
>>
>>
>> apply(Xarray, 2, NewValues,SmoothList) apply(Xarray, 2,
>> NewValues,LIST=SmoothList)
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Petr Pikal [mailto:petr.pikal@precheza.cz]
>> Gesendet: Montag, 18. September 2006 08:43
>> An: Gunther Höning; r-help@stat.math.ethz.ch
>> Betreff: Re: [R] Question on apply()
>>
>> Hi
>>
>> not much information about what can be wrong. As nobody knows your
>> Xarray and SmoothList it is hard to guess. You even omitted to show
>> what "does not work" So here are few guesses.
>>
>> predict usually expects comparable data apply(Xarray, 2,
>> NewValues,LIST=SmoothList)
>>
>>
>> HTH
>> Petr
>>
>>
>>
>>
>> On 18 Sep 2006 at 8:05, Gunther Höning wrote:
>>
>> From: Gunther Höning <gunther.hoening@ukmainz.de>
>> To: <r-help@stat.math.ethz.ch>
>> Date sent: Mon, 18 Sep 2006 08:05:28 +0200
>> Subject: [R] Question on apply()
>>
>> > Dear list,
>> >
>> > I try to do the following:
>> > I have an list of length n, with elements done by smooth.spline
>> > (SmoothList). Now I have a matrix with n rows and m columns with
>> > x-values(Xarray) Now I want ot predict the y-values. Therefor I want
>> > to take the first element of SmoothList and the first row of Xarray
>> > and predict for each element in Xarray the y value. And then take
>> > the second element of SmoothList and second row of Xarray, third row
>> > of SmoothList and third row of Xarray and so on....
>> >
>> > I tried following:
>> >
>> > NewValues <- function(x,LIST){predict(LIST,x)} apply(Xarray, 2,
>> > NewValues,SmoothList)
>> >
>> > But it don't work.
>> >
>> > Could anybody help please ?
>> >
>> > Gunther
>> >
>> > ______________________________________________
>> > R-help@stat.math.ethz.ch 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.
>>
>> Petr Pikal
>> petr.pikal@precheza.cz
>>
>
>Petr Pikal
>petr.pikal@precheza.cz
>
>______________________________________________
>R-help@stat.math.ethz.ch 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.



R-help@stat.math.ethz.ch 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. Received on Tue Sep 19 03:15:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 18 Sep 2006 - 17:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.