[R] Problems with read.table
Heberto Ghezzo
heberto at MEAKINS.Lan.McGill.CA
Tue Nov 9 11:31:27 CET 1999
Hi I am using R65.1 in Windows 95
I have a CSV file from Excell
>
a<-read.table("c:/heberto/mgc/tst.csv",header=T,sep=",")
> attach(a)
> a
manolo fvcpp fevpp fvvcpp tlcpp rvpp rvtlpp plmaxpp
1 1 99.28 97.67 98.38 91.14 102.9 111.25 117.64
2 1 86.97 68.56 78.89 94.60 112.34 118.53 159.20
3 1 81.12 71.76 88.37 89.16 114.17 126.86 60.71
4 1 98.12 86.05 87.73 102.34 127.41 123.05 102.13
5 1 90.50 80.87 89.47 85.60 93.27 107.35 86.03
--This is correct
> mean(fvcpp)
Error: "sum" not meaningful for factors
> fvcpp
[1] 99.28 86.97 81.12 98.12 90.50
Levels: 81.12 86.97 90.50 98.12 99.28
-- it reads the columns as factors and not as numeric
> rm(a)
> a<-read.table("c:/heberto/mgc/tst.csv",header=T,sep=",",as.is=F)
> attach(a)
> mean(fvcpp)
Error: "sum" not meaningful for factors
> ls()
[1] "a"
> rm(a)
> a<-read.table("c:/heberto/mgc/tst.csv",header=T,sep=",",as.is=T)
> attach(a)
> mean(fvcpp)
Error in sum(..., na.rm = na.rm) : invalid "mode" of argument
>
-- so now, how can I read the file as numeric vectors?
> fvcpp
[1] "99.28 " "86.97 " "81.12 " "98.12 " "90.50 "
> fvcpp<-as.numeric(fvcpp)
> fvcpp
[1] 99.28 86.97 81.12 98.12 90.50
> mean(fvcpp)
[1] 91.198
>
-- this is obviously not the way to do it, for each variable
change it into numeric.
Can somebody tell me what I am doing wrong?, I used to follow the same
procedure a<-read.table(... attach(a) and have all my variables as
vectors with or without NA's .
This file has no NA's is all complete.
Thanks.
..
R. Heberto Ghezzo Ph.D.
Meakins-Christie Labs
McGill University
Montreal - Canada
heberto at meakins.lan.mcgill.ca
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list