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) > amanolo 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Heberto Ghezzo" <heberto at MEAKINS.Lan.McGill.CA> writes:> -- 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.Do you have spaces before the commas in your file? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, Nov 09, 1999 at 11:31:27AM +0000, Heberto Ghezzo wrote:> Hi I am using R65.1 in Windows 95 > I have a CSV file from Excell > > 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. >If all variables are numeric, as part omitted of your message seems to point to, you can transform them in one step:> system("cat Chopin");cat("\n")1 , 2 3 , 4> a <- read.table("Chopin",sep=",") > aV1 V2 1 1 2 2 3 4> attach(a) > mean(V1)Error: "sum" not meaningful for factors But,> a <- data.frame(apply(read.table("Chopin",sep=","),2,as.numeric)) > attach(a) > mean(V1)[1] 2 On the other hand, if you have a mix of factor e/o character variables and numeric variables, things are a more complicated (and perhaps does exist a better solution than the following one):> system("cat Bartok");cat("\n")1 , two , 3 4 , five, 6> a <- read.table("Bartok",sep=",") > var.numeric <- c("V1","V3") > index <- match(var.numeric,colnames(a)) > names <- colnames(a) > a <- data.frame(apply(a[,index],2,as.numeric),a[,-index]) > colnames(a) <- c(names[index],names[-index]) > aV1 V3 V2 1 1 3 two 2 4 6 five> attach(a) > mean(V1)[1] 2.5 Hoping this help, guido -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._