write                  package:base                  R Documentation

_W_r_i_t_e _D_a_t_a _t_o _a _F_i_l_e

_D_e_s_c_r_i_p_t_i_o_n:

     The data (usually a matrix) 'x' are written to file 'file'. If 'x'
     is a two-dimensional matrix you need to transpose it to get the
     columns in 'file' the same as those in the internal
     representation.

_U_s_a_g_e:

     write(x, file = "data",
           ncolumns = if(is.character(x)) 1 else 5,
           append = FALSE, sep = " ")

_A_r_g_u_m_e_n_t_s:

       x: the data to be written out.

    file: A connection, or a character string naming the file to write
          to. If '""', print to the standard output connection. If it
          is '"|cmd"', the output is piped to the command given by
          'cmd'. 

ncolumns: the number of columns to write the data in.

  append: if 'TRUE' the data 'x' are appended to the connection.

     sep: a string used to separate columns.  Using 'sep = "\t"' gives
          tab delimited output; default is '" "'.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'write' is a wrapper for 'cat', which gives further details on the
     format used.

     'save' for writing any R objects, 'write.table' for data frames,
     and 'scan' for reading data.

_E_x_a_m_p_l_e_s:

     # create a 2 by 5 matrix
     x <- matrix(1:10,ncol=5)

     # the file data contains x, two rows, five cols
     # 1 3 5 7 9 will form the first row
     write(t(x))

     # Writing to the "console" 'tab-delimited'
     # two rows, five cols but the first row is 1 2 3 4 5
     write(x, "", sep = "\t")
     unlink("data") # tidy up

