List of tables needed

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

List of tables needed

jacksonmrodrigues@gmail.com
Dear all,


My name is Jackson and I need a help in applying functions to a list of
tables.


Could anyone help me to use loop/array on a list of tables ?

I need to apply a group of functions (listed below) to a list of tables

I am not that good with loops or arrays or multiple functions.

So, could some of you help me ?


mylist <- list.files(full.names = F, pattern =".asc$")

mylist

[1] table1.asc" " table2.asc"
[3] " table3.asc" " table4.asc  "
[5] " table5.asc  "

The <https://www.facebook.com/hashtag/the?source=feed_text&epa=HASHTAG>
following
functions should be applied to each table from mylist

######

in.r=read.table(mylist,sep="",skip=7,header=F)

cl=read.table(mylist,sep="",nrows=1,header=F)

rw=read.table(mylist,sep="",nrows=1,skip=1,header=F)

xll=read.table(mylist,sep="",nrows=1,skip=2,header=F)

yll=read.table(mylist,sep="",nrows=1,skip=3,header=F)

xdim=read.table(mylist,sep="",nrows=1,skip=4,header=F)

ydim=read.table(mylist,sep="",nrows=1,skip=5,header=F)

nd=read.table(mylist,sep="",nrows=1,skip=6,header=F)


#Convert
<https://www.facebook.com/hashtag/convert?source=feed_text&epa=HASHTAG> to
Raster

in.rr=raster(as.matrix(in.r))

in.rr[in.rr == -9999]=NA

x.max=xll$V2+(xdim$V2*cl$V2)

y.max=yll$V2+(ydim$V2*rw$V2)

extent(in.rr)=c(xll$V2,x.max,yll$V2,y.max)

#################


Thank you all in advance.


Jackson Rodrigues

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: List of tables needed

Bert Gunter-2
?lapply

See also the"Intro to R" tutorial that ships with R. We(or at least I)
expect you to do your own homework learning basic R before posting here.
This is not a substitute for such efforts, but we are willing to help when
you get stuck. See the posting guide linked below and show us your own
coding efforts.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Jul 20, 2019 at 5:16 PM Jackson Rodrigues <
[hidden email]> wrote:

> Dear all,
>
>
> My name is Jackson and I need a help in applying functions to a list of
> tables.
>
>
> Could anyone help me to use loop/array on a list of tables ?
>
> I need to apply a group of functions (listed below) to a list of tables
>
> I am not that good with loops or arrays or multiple functions.
>
> So, could some of you help me ?
>
>
> mylist <- list.files(full.names = F, pattern =".asc$")
>
> mylist
>
> [1] table1.asc" " table2.asc"
> [3] " table3.asc" " table4.asc  "
> [5] " table5.asc  "
>
> The <https://www.facebook.com/hashtag/the?source=feed_text&epa=HASHTAG>
> following
> functions should be applied to each table from mylist
>
> ######
>
> in.r=read.table(mylist,sep="",skip=7,header=F)
>
> cl=read.table(mylist,sep="",nrows=1,header=F)
>
> rw=read.table(mylist,sep="",nrows=1,skip=1,header=F)
>
> xll=read.table(mylist,sep="",nrows=1,skip=2,header=F)
>
> yll=read.table(mylist,sep="",nrows=1,skip=3,header=F)
>
> xdim=read.table(mylist,sep="",nrows=1,skip=4,header=F)
>
> ydim=read.table(mylist,sep="",nrows=1,skip=5,header=F)
>
> nd=read.table(mylist,sep="",nrows=1,skip=6,header=F)
>
>
> #Convert
> <https://www.facebook.com/hashtag/convert?source=feed_text&epa=HASHTAG> to
> Raster
>
> in.rr=raster(as.matrix(in.r))
>
> in.rr[in.rr == -9999]=NA
>
> x.max=xll$V2+(xdim$V2*cl$V2)
>
> y.max=yll$V2+(ydim$V2*rw$V2)
>
> extent(in.rr)=c(xll$V2,x.max,yll$V2,y.max)
>
> #################
>
>
> Thank you all in advance.
>
>
> Jackson Rodrigues
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: List of tables needed

David Winsemius
In reply to this post by jacksonmrodrigues@gmail.com

On 7/20/19 5:17 PM, Jackson Rodrigues wrote:

> Dear all,
>
>
> My name is Jackson and I need a help in applying functions to a list of
> tables.
>
>
> Could anyone help me to use loop/array on a list of tables ?
>
> I need to apply a group of functions (listed below) to a list of tables
>
> I am not that good with loops or arrays or multiple functions.
>
> So, could some of you help me ?

I'm not accepting the task of writing out your full project for you, but
instead will offer a game plan:

Steps to take:

-initialize empty  lists for each type of input dataset named `in.r`,
`cl` , etc.

    #e.g.

    in.r <- list()

1) start for loop indexed by:    f_n = seq_along(mylist)

2) put your read.table lines inside the for-loop body with the LHS of
the assignment having the list name indexed by the for-loop variable.

    #e.g.:

      in.r[f_n]=read.table(mylist[f_n], sep="", skip=7, header=F)

# and do learn to use spaces liberally in code

3) terminate the for-loop.

4) in the future use `library()` calls to load whatever packages have
non-base functions (eg, `raster`)

Best of luck;

David

>
>
> mylist <- list.files(full.names = F, pattern =".asc$")
>
> mylist
>
> [1] table1.asc" " table2.asc"
> [3] " table3.asc" " table4.asc  "
> [5] " table5.asc  "
>
> The <https://www.facebook.com/hashtag/the?source=feed_text&epa=HASHTAG>
> following
> functions should be applied to each table from mylist
>
> ######
>
> in.r=read.table(mylist,sep="",skip=7,header=F)
>
> cl=read.table(mylist,sep="",nrows=1,header=F)
>
> rw=read.table(mylist,sep="",nrows=1,skip=1,header=F)
>
> xll=read.table(mylist,sep="",nrows=1,skip=2,header=F)
>
> yll=read.table(mylist,sep="",nrows=1,skip=3,header=F)
>
> xdim=read.table(mylist,sep="",nrows=1,skip=4,header=F)
>
> ydim=read.table(mylist,sep="",nrows=1,skip=5,header=F)
>
> nd=read.table(mylist,sep="",nrows=1,skip=6,header=F)
>
>
> #Convert
> <https://www.facebook.com/hashtag/convert?source=feed_text&epa=HASHTAG> to
> Raster
>
> in.rr=raster(as.matrix(in.r))
>
> in.rr[in.rr == -9999]=NA
>
> x.max=xll$V2+(xdim$V2*cl$V2)
>
> y.max=yll$V2+(ydim$V2*rw$V2)
>
> extent(in.rr)=c(xll$V2,x.max,yll$V2,y.max)
>
> #################
>
>
> Thank you all in advance.
>
>
> Jackson Rodrigues
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.