Re: [R] how to loop this?[Solved]

From: antonio rodriguez <antonio.raju_at_gmail.com>
Date: Fri 24 Nov 2006 - 10:34:46 GMT

Petr Pikal escribió:
> Hi
>
> when working with lists, considerable option is to look on lapply,
> sapply, mapply or other *apply functions. If I am not mistaken you
> can do
>
> ttt<-lapply(lasker, function(x)
> data.frame(table(substr(names(subset(x, x >=4)), 1, 7))))
>
> to get a list with desired output.
>
> HTH
> Petr
>

Dear Petr,

It works great!!

Many Thanks,

Antonio

>
> On 23 Nov 2006 at 21:06, antonio rodriguez wrote:
>
> Date sent: Thu, 23 Nov 2006 21:06:18 +0100
> From: antonio rodriguez <antonio.raju@gmail.com>
> To: R-Help <r-help@stat.math.ethz.ch>
> Subject: [R] how to loop this?
>
>
>> Hi,
>>
>> I have the next procedure:
>>
>> t1<-data.frame(table(substr(names(subset(lasker[[1]], lasker[[1]] >=
>> 4)), 1, 7)))
>>
>> t1[1:5,]
>>
>> Var1 Freq
>> 1 1988-02 3
>> 2 1988-03 1
>> 3 1988-04 1
>> 4 1988-05 2
>> 5 1988-06 3
>>
>> How to make a new list?, dataframe? having 189 elements in the
>> 'lasker' list:
>>
>> > str(lasker[[1]])
>> 'table' int [, 1:1274] 1 1 3 2 1 5 4 1 1 4 ...
>> - attr(*, "dimnames")=List of 1
>> ..$ : chr [1:1274] "1988-01-13" "1988-01-16" "1988-01-20"
>> "1988-01-25" ...
>> .
>> .
>> > str(lasker[[189]])
>> 'table' int [, 1:464] 1 1 4 1 4 4 6 2 3 3 ...
>> - attr(*, "dimnames")=List of 1
>> ..$ : chr [1:464] "1999-07-21" "1999-07-23" "1999-07-25"
>> "1999-07-31" ...
>>
>>
>> I've tried:
>>
>> windows<-vector("list",189)
>>
>> for (i in 1:189){
>> windows[[i]]<-data.frame(table(substr(names(subset(lasker[[i]],
>> lasker[[i]] >= 4)), 1, 7)))
>> }
>>
>> Erro en rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
>> invalid number of copies in rep.int()
>>
>> I think this is due because each new element (like t1) has 2 columns.
>> But what kind of structure is needed to accomodate the new elements?
>>
>> Thanks
>>
>> Antonio
>>



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 Fri Nov 24 21:34:51 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 Fri 24 Nov 2006 - 11:30:18 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.