[R] Reading in tab (and space) delimited data within a scriptXXXX
Daniel Nordlund
djnordlund at frontier.com
Thu Jan 19 20:00:31 CET 2012
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Dan Abner
> Sent: Thursday, January 19, 2012 8:51 AM
> To: R. Michael Weylandt
> Cc: r-help at r-project.org
> Subject: Re: [R] Reading in tab (and space) delimited data within a
> scriptXXXX
>
> 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
> + 2870-9965324.31.422
> + 2974F613250.872
> + 3074F62323.30.942"
> >
> >
> > data3<-read.table(textConnection(data3),
> + header=TRUE,sep=" ",
> + row.names="OBSNO")
> Error in data[[rowvar]] : attempt to select less than one element
> > closeAllConnections()
> > data3
> [1]
> "OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180
> .843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200
> .972\n2771F109322.30.942\n2870-
> 9965324.31.422\n2974F613250.872\n3074F62323.30.942"
> >
>
> > data3<-read.table(textConnection(data3),
> + header=TRUE,sep="\t",
> + row.names="OBSNO")
> Error in data[[rowvar]] : attempt to select less than one element
> > closeAllConnections()
> > data3
> [1]
> "OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180
> .843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200
> .972\n2771F109322.30.942\n2870-
> 9965324.31.422\n2974F613250.872\n3074F62323.30.942"
> >
>
>
Dan,
Reading the data works fine for me on a Win7 x64 system using R-2.14.1 using the following.
data3<-
"OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
21 76 M 84 5 3.2 0.9 3
22 76 M 5 2.18 0.84 3
23 68 M 82 5 2.15 0.52 1
24 69 M 84 5 2.3 1.36 1
25 76 F 100 3 25.3 1.07 3
26 70 F 90 3 20 0.97 2
27 71 F 109 3 22.3 0.94 2
28 70 -99 65 3 24.3 1.42 2
29 74 F 61 3 25 0.87 2
30 74 F 62 3 23.3 0.94 2"
df <- read.table(textConnection(data3), header=TRUE, sep=' ',
na.strings='-99', row.names='OBSNO')
Something may have become corrupted on your system. Try restarting R and re-running the code. If that doesn't solve the problem, then you may need to show us exactly the code you are executing, and provide relevant information about your OS and version of R with sessionInfo().
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA USA
More information about the R-help
mailing list