Skip to content

Read text file

3 messages · Steven Yen, William Dunlap, Olivier Crouzet

#
How do I read a block of space-delimited numbers into a column vector 
using the read.table command? Thank you.
#
I am not sure what you mean by "a block", but you can probably use
scan() instead of read.table():
  > txt <- "1 21 41 61 81"
  > d <- data.frame(Numbers=scan(text=txt, what="numeric", quiet=TRUE))
  > d
    Numbers
  1       1
  2      21
  3      41
  4      61
  5      81


Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Wed, Jun 17, 2015 at 10:10 PM, Steven Yen <syen04 at gmail.com> wrote:

            

  
  
#
Hi, 

I think that you need scan() but you should at least give us an example of your text data.

Olivier.

--
Olivier Crouzet
LLING - Laboratoire de Linguistique de Nantes - EA3827
Universit? de Nantes

-----Original Message-----
From: Steven Yen <syen04 at gmail.com>
Sender: "R-help" <r-help-bounces at r-project.org>Date: Thu, 18 Jun 2015 01:10:39 
To: r-help<r-help at r-project.org>
Reply-To: syen04 at gmail.com
Subject: [R] Read text file

How do I read a block of space-delimited numbers into a column vector 
using the read.table command? Thank you.