[R] clear workspace

2007-08-01 Thread Dong GUO
Dear all,

How can I clear the workspace, as we do in Matlab "clear all"??

Many thanks in advance.

Dong

[[alternative HTML version deleted]]

__
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.


Re: [R] array loop

2007-08-01 Thread Dong GUO
Thanks again, Petr. Following the reference, that would be true that "="
only assign values to the top level...So apparently using '<-' is the safe
all the time to assign values.

Dong


On 8/1/07, Petr PIKAL <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> "Dong GUO ¹ù¶«" <[EMAIL PROTECTED]> napsal dne 31.07.2007 15:27:35:
>
> > Thanks, Petr.
> >
> > I changed the equation mark from "=" to "<-", then, it works fine. Dont
> know
> > what difference it has made between the "=" and "<-"..
>
> from help page
>
> The operators <- and = assign into the environment in which they are
> evaluated. The operator<- can be used anywhere, whereas the operator = is
> only allowed at the top level (e.g., in the complete expression typed at
> the command prompt) or as one of the subexpressions in a braced list of
> expressions.
>
> Although I do not fully understand where I can use <- and where =, to be
> on safe side I use <- everywhere when I want to do assignment of some
> value(s).
>
> Regards
>
> Petr
>
> >
> > Regards,
> > Dong
>
> > On 7/31/07, Petr PIKAL <[EMAIL PROTECTED]> wrote:
> > Hi
> >
> > as you say that the computing is part of a function than the best way to
> > see what is hapenning is to use
> >
> > debug(your.function)
> >
> > see ?debug for options.
> >
> > Regards
> >
> > Petr
> > [EMAIL PROTECTED]
> >
> > [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00:
> >
> > > Dear all,
> > >
> > > here are two arrays: region(26,31,8), nation(8)
> > >
> > > I tried to get a new array, say, giGi(26,31,8)
> > >
> > > giGi <- array(0,dim = c(region_dim))
> > >
> > > for (i in (1:region_dim[3]))
> > > {
> > > giGi[,,i] = region[,,i]-nation[,i]
> > >
> > > }
> > >
> > > As the above is part of function, but results shows only giGi[,,1] has
> > the
> > > right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I
> have
> > > checked array of region and nation, they are not zeros at all
> > >
> > > when I do manually, it is not the case, giGi has meanful numbers.
> > >
> > > can some one tell me the trick in this process??
> > >
> > > Many thanks in advance.
> > > Dong
> > >
> > >[[alternative HTML version deleted]]
> > >
> > > __
> > > 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.
>
>

[[alternative HTML version deleted]]

__
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.


Re: [R] array loop

2007-07-31 Thread Dong GUO
Thanks, Petr.

I changed the equation mark from "=" to "<-", then, it works fine. Dont know
what difference it has made between the "=" and "<-"..

Regards,
Dong

On 7/31/07, Petr PIKAL <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> as you say that the computing is part of a function than the best way to
> see what is hapenning is to use
>
> debug(your.function)
>
> see ?debug for options.
>
> Regards
>
> Petr
> [EMAIL PROTECTED]
>
> [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00:
>
> > Dear all,
> >
> > here are two arrays: region(26,31,8), nation(8)
> >
> > I tried to get a new array, say, giGi(26,31,8)
> >
> > giGi <- array(0,dim = c(region_dim))
> >
> > for (i in (1:region_dim[3]))
> > {
> > giGi[,,i] = region[,,i]-nation[,i]
> >
> > }
> >
> > As the above is part of function, but results shows only giGi[,,1] has
> the
> > right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I have
> > checked array of region and nation, they are not zeros at all
> >
> > when I do manually, it is not the case, giGi has meanful numbers.
> >
> > can some one tell me the trick in this process??
> >
> > Many thanks in advance.
> > Dong
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > 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.
>
>

[[alternative HTML version deleted]]

__
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.


Re: [R] write.csv

2007-07-30 Thread Dong GUO
Many thanks, Jim...


On 7/31/07, jim holtman <[EMAIL PROTECTED]> wrote:
>
> Then you can just write a 'for' loop to write out each submatrix:
>
> for (i in 1:dim(x)[3]){
> write.csv(x[,,i], paste("x", i, ".csv", sep=""))
> }
>
>
> On 7/30/07, Dong GUO ¹ù¶« <[EMAIL PROTECTED]> wrote:
> > the dim of my results is (26,31,8) -(years, regions and variables). so,
> if i
> > save each (years, regions) in 8 csv files, later, I could connect the
> > (26,31) to dbf file in ArcGIS to show in a map. This is what I intend to
> do.
> >
> > I dont know a better way to do it directly in R...
> >
> >
> > On 7/31/07, jim holtman <[EMAIL PROTECTED]> wrote:
> > > It really depends on how you want it output.  You can use 'write.csv'
> > > to write an array out and it will be a 2-dimentional image that you
> > > could then reconstruct it from if you know what the dimensions were.
> > > What do you want to do with the data?  If you are just going to read
> > > it back into R, then use save/load.
> > >
> > > On 7/29/07, Dong GUO ¹ù¶« < [EMAIL PROTECTED]> wrote:
> > > > Hi,
> > > >
> > > > I want to save an array(say, array[6,7,8]) write a cvs file. How can
> I
> > do
> > > > that??? can I write in one file?
> > > >
> > > > if I could not write in one file, i want to use a loop to save in
> > different
> > > > files (in the array[6,7,8], should be 8 csv files), such as the
> filename
> > > > structure should be: file ="filename" +str(i) +"." +"csv"
> > > >
> > > > Many thanks.
> > > >
> > > >[[alternative HTML version deleted]]
> > > >
> > > > __
> > > > 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.
> > > >
> > >
> > >
> > > --
> > > Jim Holtman
> > > Cincinnati, OH
> > > +1 513 646 9390
> > >
> > > What is the problem you are trying to solve?
> > >
> >
> >
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>

[[alternative HTML version deleted]]

__
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.


Re: [R] write.csv

2007-07-30 Thread Dong GUO
the dim of my results is (26,31,8) -(years, regions and variables). so, if i
save each (years, regions) in 8 csv files, later, I could connect the
(26,31) to dbf file in ArcGIS to show in a map. This is what I intend to do.


I dont know a better way to do it directly in R...

On 7/31/07, jim holtman <[EMAIL PROTECTED]> wrote:
>
> It really depends on how you want it output.  You can use 'write.csv'
> to write an array out and it will be a 2-dimentional image that you
> could then reconstruct it from if you know what the dimensions were.
> What do you want to do with the data?  If you are just going to read
> it back into R, then use save/load.
>
> On 7/29/07, Dong GUO ¹ù¶« <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I want to save an array(say, array[6,7,8]) write a cvs file. How can I
> do
> > that??? can I write in one file?
> >
> > if I could not write in one file, i want to use a loop to save in
> different
> > files (in the array[6,7,8], should be 8 csv files), such as the filename
> > structure should be: file ="filename" +str(i) +"." +"csv"
> >
> > Many thanks.
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > 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.
> >
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>

[[alternative HTML version deleted]]

__
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.


Re: [R] write.csv

2007-07-30 Thread Dong GUO
Thanks Ted for the help. I will try and see if my case will get the expected
results.

Dong

On 7/30/07, Ted Harding <[EMAIL PROTECTED]> wrote:
>
> On 29-Jul-07 17:41:58, Dong GUO ¹ù¶« wrote:
> > Hi,
> >
> > I want to save an array(say, array[6,7,8]) write a cvs file.
> > How can I do that??? can I write in one file?
> >
> > if I could not write in one file, i want to use a loop to save
> > in different files (in the array[6,7,8], should be 8 csv files),
> > such as the filename structure should be:
> > file ="filename" +str(i)+"." +"csv"
> >
> > Many thanks.
>
> The following (illustrated on a smaller array) may help:
>
> A<-array((1:60),dim=c(3,4,5))
> D<-dim(A)
>
> write.table(t(dim(A)),file="A.csv",sep=",",
> quote=FALSE,row.names=FALSE,col.names=FALSE)
>
> Z<-as.vector(A)
> write.table(t(Z),file="A.csv",append=TRUE,sep=",",
> quote=FALSE,row.names=FALSE,col.names=FALSE)
>
> Then the file A.csv contains two rows:
>
> 3,4,5
> 1,2,3,4,5,6,7,8,9,10,11,12, ... ,55,56,57,58,59,60
>
> of which the first gives the dimension, the second the
> data for the array.
>
> You can then reconstruct another array, say B, as:
>
> dimB<-scan(file="A.csv",sep=",",nlines=1)
> dataB<-scan(file="A.csv",sep=",",skip=1,nlines=1)
> B<-array(dataB,dimB)
>
> That's a hard way to do things, perhaps, but since you said
> you wanted the array as a CSV file, this is one way to do that.
>
> Since a CSV text file is essentially a two-dimensional object
> (fields in rows, by rows), to store a higher-dimensional object
> in such a format you have to include the "meta-data" about the
> structure -- in this case the list of dimensions.
>
> Note, however, that, although it is a CSV file,
>
> read.csv("A.csv",header=FALSE)
>
> will not work nicely, since it will give you two rows of equal
> length, the first one padded out with (in this case 57) NAs,
> which you will then have to clean up; which you can do, but by
> the time you've done it you might as well have done it the above
> way!
>
> Hoping this helps,
> Ted.
>
> 
> E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
> Fax-to-email: +44 (0)870 094 0861
> Date: 30-Jul-07   Time: 22:24:12
> -- XFMail --
>

[[alternative HTML version deleted]]

__
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] array loop

2007-07-30 Thread Dong GUO
Dear all,

here are two arrays: region(26,31,8), nation(8)

I tried to get a new array, say, giGi(26,31,8)

giGi <- array(0,dim = c(region_dim))

for (i in (1:region_dim[3]))
{
giGi[,,i] = region[,,i]-nation[,i]

}

As the above is part of function, but results shows only giGi[,,1] has the
right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I have
checked array of region and nation, they are not zeros at all

when I do manually, it is not the case, giGi has meanful numbers.

can some one tell me the trick in this process??

Many thanks in advance.
Dong

[[alternative HTML version deleted]]

__
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.


Re: [R] array writing and their filenames

2007-07-30 Thread Dong GUO
Many thanks to Edna and Roland.
I followed the suggestions, and it worked well.

Regards,
Dong

On 7/30/07, Edna Bell <[EMAIL PROTECTED]> wrote:
>
> > #Original 3x4x2 array
> > xb
> , , 1
>
>  [,1] [,2] [,3] [,4]
> [1,]  0.4  0.9  5.6  0.1
> [2,]  0.3  2.3  3.3  0.7
> [3,]  0.6  0.8  0.2  0.7
>
> , , 2
>
>  [,1] [,2] [,3] [,4]
> [1,]  0.4  0.9  5.6  0.1
> [2,]  0.3  2.3  3.3  0.7
> [3,]  0.6  0.8  0.2  0.7
>
> > for(i in 1:2) {
> + write(file="stuff4",t(xb[,,i]),ncol=4,append=T)
> + xx <- paste("end of array ",i,sep="")
> + write(file="stuff4",xx,append=T)
> + }
> > file.show("stuff4")
> > #All is well
> >
>
>
> On 7/29/07, Dong GUO ¹ù¶« <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I want to save a array (say, array[6,7,8]) write a cvs file. How can I
> do
> > that??? can I write in one file?
> >
> > if I could not write in one file, i want to use a loop to save in
> different
> > files (in the matrix[6,7,8], should be 8 csv files), such as the
> filename
> > structure should be: file ="filename" +str(i) +"." +"csv"
> >
> > Many thanks.
> > Dong
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > 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.
> >
>

[[alternative HTML version deleted]]

__
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] filenames

2007-07-30 Thread Dong GUO
Dear all,

I want to create filename from a loop, say, i=(1:10), and the final names
will be file1.csv, file2.csv, file3.csv

in Python, it seems easer as -  "file"+str(i) +'.csv , but how can i do in R

> list = as.character(1:10)
> list
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

[[alternative HTML version deleted]]

__
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] write.csv

2007-07-30 Thread Dong GUO
Hi,

I want to save an array(say, array[6,7,8]) write a cvs file. How can I do
that??? can I write in one file?

if I could not write in one file, i want to use a loop to save in different
files (in the array[6,7,8], should be 8 csv files), such as the filename
structure should be: file ="filename" +str(i) +"." +"csv"

Many thanks.

[[alternative HTML version deleted]]

__
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.


Re: [R] plot

2007-07-30 Thread Dong GUO
Thanks again, Greg, It really helps.

Would you please let me know more reference of plot in R?  how to use the
image function to create the grid???

Thanks much.
Dong

On 7/27/07, Greg Snow <[EMAIL PROTECTED]> wrote:
> Can you really see much of the data in a 26*31 3d barplot?  It seems like
most info would be hidden behind the first few rows and it would be so
cluttered that you would not be able to make out much of anything from it.
>

It is true that with too much info in such a 3d graph, it would be not
informative.

> Why not try a line plot instead (year as the x axis, each region a
different year).  Here is a quick example:
>
> > data(votes.repub, package='cluster')
> > matplot( t(votes.repub[1:31, 1:26]), type='l')
> >
>
> Even better would be to group some of the regions together and use xyplot
from the lattice package and have a panel for each group of regions (fewer
lines per panel should be easier to see detail).
>
> You could also use the image function (or levelplot from lattice) to
create a 26*31 grid with colors used for the 3rd dimension (can be good for
overall patterns, not so good for looking at detail).
>
> Hope this helps,
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [EMAIL PROTECTED]
> (801) 408-8111
>
>
>
> > -Original Message-
> > From: Dong GUO ¹ù¶« [mailto:[EMAIL PROTECTED]
> > Sent: Friday, July 27, 2007 12:09 PM
> > To: Greg Snow
> > Cc: r-help@stat.math.ethz.ch
> > Subject: Re: [R] plot
> >
> > Many thanks, Greg and Justin.
> >
> > The matrix is just a 26*31 matrix - 26 years, 31 regions. I
> > am know to R, just dont know how to attach the data here yet..
> >
> > As I have such matrices for nine indicators for all regions,
> > so i could show some differences by 3D plot, which I did
> > similar things in Excel. I am sure there is a way to do it in R
> >
> > On 7/27/07, Greg Snow < [EMAIL PROTECTED]> wrote:
> > > Graphs that rely on 3-d effects tend to distort the data
> > rather than enlighten the viewer.  If your goal is to distort
> > the data (which I doubt), then most of us don't want to help.
> >  On the other hand, if you really do want to enlighten the
> > viewer (even if that is just you), then tell us what your
> > data is like and what you want to learn from it, and we will
> > be happy to give you advice on creating useful graphs.
> > >
> > > --
> > > Gregory (Greg) L. Snow Ph.D.
> > > Statistical Data Center
> > > Intermountain Healthcare
> > > [EMAIL PROTECTED]
> > > (801) 408-8111
> > >
> > >
> > >
> > > > -Original Message-
> > > > From: [EMAIL PROTECTED]
> > > > [mailto:[EMAIL PROTECTED] ] On Behalf Of Dong GUO ??
> > > > Sent: Friday, July 27, 2007 8:45 AM
> > > > To: r-help@stat.math.ethz.ch
> > > > Subject: [R] plot
> > > >
> > > > Greetings to the group,
> > > >
> > > > I would like to know if some one could help me with plot
> > 3-d column
> > > > graph of a matrix (3-d column graph in Excel).
> > > >
> > > > Many thanks in advance.
> > > >
> > > > Regards,
> > > > Dong
> > > >
> > > > __
> > > > 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.
> > > >
> > >
> > >
> >
>
>

[[alternative HTML version deleted]]

__
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] matrix output in R, and file name creating

2007-07-30 Thread Dong GUO
Hi,

I want to save a matrix (say, matrix[6,7,8]) write a cvs file. How can I do
that??? can I write in one file?

if I could not write in one file, i want to use a loop to save in different
files (in the matrix[6,7,8], should be 8 csv files), such as the filename
structure should be: file ="filename" +str(i) +"." +"csv"

Many thanks.
Dong

[[alternative HTML version deleted]]

__
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] array writing and their filenames

2007-07-30 Thread Dong GUO
Hi,

I want to save a array (say, array[6,7,8]) write a cvs file. How can I do
that??? can I write in one file?

if I could not write in one file, i want to use a loop to save in different
files (in the matrix[6,7,8], should be 8 csv files), such as the filename
structure should be: file ="filename" +str(i) +"." +"csv"

Many thanks.
Dong

[[alternative HTML version deleted]]

__
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.


Re: [R] plot

2007-07-30 Thread Dong GUO
Many thanks, Greg and Justin.

The matrix is just a 26*31 matrix - 26 years, 31 regions. I am know to
R, just dont know how to attach the data here yet..

As I have such matrices for nine indicators for all regions, so i
could show some differences by 3D plot, which I did similar things in
Excel. I am sure there is a way to do it in R

On 7/27/07, Greg Snow <[EMAIL PROTECTED]> wrote:
> Graphs that rely on 3-d effects tend to distort the data rather than 
> enlighten the viewer.  If your goal is to distort the data (which I doubt), 
> then most of us don't want to help.  On the other hand, if you really do want 
> to enlighten the viewer (even if that is just you), then tell us what your 
> data is like and what you want to learn from it, and we will be happy to give 
> you advice on creating useful graphs.
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [EMAIL PROTECTED]
> (801) 408-8111
>
>
>
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Dong GUO ??
> > Sent: Friday, July 27, 2007 8:45 AM
> > To: r-help@stat.math.ethz.ch
> > Subject: [R] plot
> >
> > Greetings to the group,
> >
> > I would like to know if some one could help me with plot 3-d
> > column graph of a matrix (3-d column graph in Excel).
> >
> > Many thanks in advance.
> >
> > Regards,
> > Dong
> >
> > __
> > 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.


[R] plot

2007-07-27 Thread Dong GUO
Greetings to the group,

I would like to know if some one could help me with plot 3-d column
graph of a matrix (3-d column graph in Excel).

Many thanks in advance.

Regards,
Dong

__
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.