Re: [R] write.csv / string extraction and field limits

2007-09-10 Thread Xavier Abulker

This example works fine:

test-matrix(c(1,2,'VOICIUNPETITTES',3),ncol=2,nrow=2)
write.csv(test,file='C:/xavier/test.csv')


Could you provide the same small example when it doesn't work?



kwaj wrote:
 
 Hello, 
 
 I have a peculiar problem which I am hoping I can get help on. 
 
 I am using the write.csv command to write a matrix structure to a file,
 which I later read in excel. The command works quite well for most strings
 and numerical values in the matrix structure. 
 
 However, I have found that when a field in the matrix contains a string of
 long length, when the matrix is finally written the file - the field shows
 up as NA. I am assuming write.csv has a limit on the field size? Maybe
 16 characters?
 
 Assuming the above is correct - I tried to extract a portion of the string
 using the 'substring' command and enter the extracted portion into the
 field before using the write.csv command. However I find, that when a
 string is extracted, the output from write.csv generates a NA in the file
 output. 
 
 My questions are:
 
 1) Does write.csv have a limit on the size of strings in the matrix
 fields? Is there anyway to place large strings in the field?
 
 2) Is there anyway to make the substring command or an alternative but
 similar command, compatible with write.csv? I have tried
 'as.character(substring(phrase, min, max)' and that does not seem to work
 
 cheers
 
 
 

-- 
View this message in context: 
http://www.nabble.com/write.csv---string-extraction-and-field-limits-tf4395535.html#a12596551
Sent from the R help mailing list archive at Nabble.com.

__
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 / string extraction and field limits

2007-09-06 Thread kwaj

Hello, 

I have a peculiar problem which I am hoping I can get help on. 

I am using the write.csv command to write a matrix structure to a file,
which I later read in excel. The command works quite well for most strings
and numerical values in the matrix structure. 

However, I have found that when a field in the matrix contains a string of
long length, when the matrix is finally written the file - the field shows
up as NA. I am assuming write.csv has a limit on the field size? Maybe 16
characters?

Assuming the above is correct - I tried to extract a portion of the string
using the 'substring' command and enter the extracted portion into the field
before using the write.csv command. However I find, that when a string is
extracted, the output from write.csv generates a NA in the file output. 

My questions are:

1) Does write.csv have a limit on the size of strings in the matrix fields?
Is there anyway to place large strings in the field?

2) Is there anyway to make the substring command or an alternative but
similar command, compatible with write.csv? I have tried
'as.character(substring(phrase, min, max)' and that does not seem to work

cheers


-- 
View this message in context: 
http://www.nabble.com/write.csv---string-extraction-and-field-limits-tf4395535.html#a12534347
Sent from the R help mailing list archive at Nabble.com.

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


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 jim holtman
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?

__
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 Ted Harding
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 --

__
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 feature/bug with pipe

2007-03-25 Thread Prof Brian Ripley
This is simply user error: the column names _are_ written to the pipe.
Because the connection was not open, the connection is opened to write the 
column names, closed, opened to write the data and then closed.

In any case, you should call close() on connections you create to avoid 
leaking connection structures.  The following works:

con - pipe(cat  d2.csv, w)
write.csv(d, file=con)
close(con)

write.table() does exactly the same thing.

On Sun, 11 Mar 2007, ivo welch wrote:

 gentoo linux, version 2.4.1:

 d= as.data.frame(matrix(1:20, 4, 5))
 d
  V1 V2 V3 V4 V5
 1  1  5  9 13 17
 2  2  6 10 14 18
 3  3  7 11 15 19
 4  4  8 12 16 20
 write.csv(d, file=d1.csv);
 write.csv(d, file=pipe(cat  d2.csv))
 write.csv(d, file=pipe(gzip -c  d3.csv.gz), col.names=T)
 Warning message:
 attempt to change 'col.names' ignored in: write.csv(d, file =
 pipe(gzip -c  d4.csv.gz), col.names = T)

(Seems unlikely the message got the file name wrong here.)

 exit and

 $ head d1.csv
 ,V1,V2,V3,V4,V5
 1,1,5,9,13,17
 2,2,6,10,14,18
 3,3,7,11,15,19
 4,4,8,12,16,20
 $ head d2.csv
 1,1,5,9,13,17
 2,2,6,10,14,18
 3,3,7,11,15,19
 4,4,8,12,16,20

 is it a bug or a feature that when pipe is used, the col.names is set
 to false?  I guess I can invoke write.table to get the headers back.

 regards,

 /iaw

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


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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 feature/bug with pipe

2007-03-11 Thread ivo welch
gentoo linux, version 2.4.1:

 d= as.data.frame(matrix(1:20, 4, 5))
 d
  V1 V2 V3 V4 V5
1  1  5  9 13 17
2  2  6 10 14 18
3  3  7 11 15 19
4  4  8 12 16 20
 write.csv(d, file=d1.csv);
 write.csv(d, file=pipe(cat  d2.csv))
 write.csv(d, file=pipe(gzip -c  d3.csv.gz), col.names=T)
Warning message:
attempt to change 'col.names' ignored in: write.csv(d, file =
pipe(gzip -c  d4.csv.gz), col.names = T)

exit and

$ head d1.csv
,V1,V2,V3,V4,V5
1,1,5,9,13,17
2,2,6,10,14,18
3,3,7,11,15,19
4,4,8,12,16,20
$ head d2.csv
1,1,5,9,13,17
2,2,6,10,14,18
3,3,7,11,15,19
4,4,8,12,16,20

is it a bug or a feature that when pipe is used, the col.names is set
to false?  I guess I can invoke write.table to get the headers back.

regards,

/iaw

__
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 + appending output (FILE I/O)

2006-05-18 Thread Sachin J
Hi,
   
  How can I write the output to an excel (csv) file without printing row names 
(i.e without breaks). Here is my code: 
   
  library(
   
  fn - function()
{
 q - c(1,2,3)
 write.csv(q,C:/Temp/op.xls, append = TRUE, row.names = FALSE,quote = FALSE)
}
   
  # Function Call
  for(i in 1:3)
{
  fn()
}
   
  Present Output :
  x123x123x123
   
  Desired output:
  1
  2
  3
  1
  2
  3
  1
  2
  3
   
  Also it displays following warning messages. 
   
  Warning messages:
1: appending column names to file in: write.table(q, C:/Temp/op.xls,  
2: appending column names to file in: write.table(q, C:/Temp/op.xls,  
3: appending column names to file in: write.table(q, C:/Temp/op.xls,  

  I am using R2.2.1 windows version. I tried using write.xls from marray 
package but no success. 
   
  Thanx in advance.
   
  Sachin

__



[[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


Re: [R] write.csv + appending output (FILE I/O)

2006-05-18 Thread Jason Barnhart
When submitting your example under R.2.3.0  WinXP, the resulting xls file 
was output row-wise as requested.  See results below. Not sure why yours 
outputs columnar-wise.

To drop the variable name set col.names=FALSE. Note that the write.csv 
wrapper is designed to be inflexible and that you will need to use 
write.table instead.  Here's a qoute from ?write.csv

These wrappers are deliberately inflexible: they are designed to
 ensure that the correct conventions are used to write a valid
 file. Attempts to change 'col.names', 'sep', 'dec' or 'qmethod'
 are ignored, with a warning.

HTH,
-jason


Results from Sachin code.
** Begin XLS File ***
  x
  1
  2
  3
  x
  1
  2
  3
  x
  1
  2
  3


** End XLS File ***


- Original Message - 
From: Sachin J [EMAIL PROTECTED]
To: R-help@stat.math.ethz.ch
Sent: Thursday, May 18, 2006 7:36 AM
Subject: [R] write.csv + appending output (FILE I/O)


 Hi,

  How can I write the output to an excel (csv) file without printing row 
 names (i.e without breaks). Here is my code:

  library(

  fn - function()
 {
 q - c(1,2,3)
 write.csv(q,C:/Temp/op.xls, append = TRUE, row.names = FALSE,quote = 
 FALSE)
 }

  # Function Call
  for(i in 1:3)
 {
  fn()
 }

  Present Output :
  x123x123x123

  Desired output:
  1
  2
  3
  1
  2
  3
  1
  2
  3

  Also it displays following warning messages.

  Warning messages:
 1: appending column names to file in: write.table(q, C:/Temp/op.xls,
 2: appending column names to file in: write.table(q, C:/Temp/op.xls,
 3: appending column names to file in: write.table(q, C:/Temp/op.xls,

  I am using R2.2.1 windows version. I tried using write.xls from marray 
 package but no success.

  Thanx in advance.

  Sachin

 __



 [[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


__
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