...@r-project.org] On
Behalf Of Jeff Newmiller
Sent: Thursday, January 19, 2012 11:24 AM
To: Dan Abner; R. Michael Weylandt
Cc: r-help@r-project.org
Subject: Re: [R] Reading in tab (and space) delimited data within a script
Cannot see what you are "doing" wrong, since you don't show that
I can't reproduce your problem: both of these work just fine for me.
read.table(text = data3, header = TRUE, sep = " ", row.names = "OBSNO")
read.table(textConnection(data3), header = TRUE, sep = " ", row.names
= "OBSNO", na.string = "-99")
dput(data3)
"OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL
Cannot see what you are "doing" wrong, since you don't show that. It looks like
you have eliminated all delimiters from your input data. Perhaps your editor
settings are doing something to your data (though usually tabs if altered
become spaces).
-
On Jan 19, 2012, at 11:37 AM, Dan Abner wrote:
Hello everyone,
I use Bob Muenchen's approach for reading in "in-stream" (to use SAS
parlance) delimited data within a script. This works great:
mystring <-
"id,workshop,gender,q1,q2,q3,q4
1,1,f,1,1,5,1
2,2,f,2,1,4,1
3,1,f,2,2,4,3
4,2, ,3,1, ,3
Hi Michael,
Thanks for your responses.
When I do this, I am not successful. What am I doing wrong?
> data3<-
+ "OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP
+ 2176M8453.20.93
+ 2276M52.180.843
+ 2368M8252.150.521
+ 2469M8452.31.361
+ 2576F100325.31.073
+ 2670F903200.972
+ 2771F109322.30.942
+ 287
Simply change the sep = "," argument of read table: " " for a space
and "\t" for a tab. E.g., read.table(text = data3, sep = " ", header =
TRUE)
Take a look at ?read.table for more info about the sep argument (In
particular the special behavior of the default sep = "")
Thanks for the well-posed
Hello everyone,
I use Bob Muenchen's approach for reading in "in-stream" (to use SAS
parlance) delimited data within a script. This works great:
mystring <-
"id,workshop,gender,q1,q2,q3,q4
1,1,f,1,1,5,1
2,2,f,2,1,4,1
3,1,f,2,2,4,3
4,2, ,3,1, ,3
5,1,m,4,5,2,4
6,2,m,5,4,5,5
7,1,m,5,3,4,4
8
7 matches
Mail list logo