[R] accessing members of a list

Pascal Oettli kridox at ymail.com
Fri Mar 28 08:30:28 CET 2014


Hello,

You are right, the "which" option avoid the selection in my example.

Also, I think ?"[[" might be helpful for you.

Regards.
Pascal

On Fri, Mar 28, 2014 at 3:02 PM, Bill <william108 at gmail.com> wrote:
> Hi. I found that this works:
> tt=readHTMLTable(url,header=TRUE, as.data.frame=TRUE,which=c(3))
> tt[1,]
> I thought I tried what you suggested but it was not working but I guess not.
> So all my errors revolved around the fact that
> mylist[] will return a slice of a list and hence still a list but
> mylist[[]] returns the data structure of that particular element?
>
> Thanks.
>
>
>
> On Fri, Mar 28, 2014 at 2:49 PM, Pascal Oettli <kridox at ymail.com> wrote:
>>
>> Hello,
>>
>> Your example leads to error. Anyway:
>>
>> library(XML)
>> oneurl="http://www.tutiempo.net/en/Climate/FUKUSHIMA/11-2012/475950.htm"
>> temp.tables=readHTMLTable(oneurl, header=TRUE)
>>
>> temp.tables <- temp.tables[[3]]
>> temp.tables <- temp.tables[1:30,]
>>
>> HTH,
>> Pascal
>>
>>
>> On Fri, Mar 28, 2014 at 2:42 PM, Bill <william108 at gmail.com> wrote:
>> > Hi. I ran some code and I am trying to access the table with the data in
>> > it. I want in particular to delete the 31st row for example
>> > Monthly means and totals: <NA> <NA> <NA>   <NA> <NA>  <NA> <NA> <NA>
>> > <NA>
>> > <NA> <NA> <NA> <NA>
>> > or remove the names of the columns (or change them). Day    T   TM   Tm
>> >  SLP    H    PP   VV    V   VM   VG   RA   SN   TS
>> >
>> > I tried all sorts of things but they don't give me access:
>> >
>> > library(XML)
>> > oneurl="http://www.tutiempo.net/en/Climate/FUKUSHIMA/11-2012/475950.htm"
>> > allFuku=data.frame() #need to initialize it with column names
>> > temp.tables=readHTMLTable(url)
>> >
>> > temp.tables[3][2]
>> > temp.tables[3]
>> > temp.tables[3][3]
>> > temp.tables[3][2,]
>> > str(temp.tables[3])
>> > temp.tables[3][2,2]
>> > dim(temp.tables[3])
>> > temp.tables[3]$SN
>> > temp.tables[3][1]
>> > temp.tables[3][1][2,]
>> > str(temp.tables[3][1])
>> > temp.tables[3][1]$SN
>> >  temp.tables[3][1][1][2,]
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at 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.
>>
>>
>>
>> --
>> Pascal Oettli
>> Project Scientist
>> JAMSTEC
>> Yokohama, Japan
>
>



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan




More information about the R-help mailing list