Hi I am really new using R, so this is really a beginner stuff! I created a very small data set on excel and then converted it to .csv file. I am able to open the data on R using the command "read.table ("mydata1.csv", sep=",", header=T)" and it just works fine. But when I want to work on the data (e.g. calculate the mean of variable "X") R says "object not found". I tried the "attach" command or "mean ("mydata1.csv"&X)" but still I get the same error message. I don't understand why R is having difficulty finding a variable. I believe I am doing something wrong. I will really appreciate if you could help me with this. [[alternative HTML version deleted]]
hello, The error message is right, you have read the file have NOT assigned it to an object, to a variable. mydata1 <- read.table ("mydata1.csv", sep=",", header=T) Now you can use the variable 'mydata1'. It's a data.frame, and you can see what it looks like with the following instructions. str(mydata1) # str for structure head(mydata1) # default is first 6 lines Note also that you could have called your dataset a name different from the filename.> mean ("mydata1.csv"&X)Where have you found that syntax??? Correct mean(mydata1$X) mean(mydata1[ , "X" ]) You should read R-intro.pdf, it comes with any installation of R, folder doc. There are obvious "beginner stuff" things you could quickly learn. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/reading-data-into-R-tp4630069p4630071.html Sent from the R help mailing list archive at Nabble.com.
You need to assign your data set to something -- right now you're just reading it in and then throwing it away: dats <- read.csv("mydata1.csv") mean(dats$X) # Dollar sign, not ampersand Best, Michael On Tue, May 15, 2012 at 8:57 AM, jacaranda tree <myjacaranda at yahoo.com> wrote:> Hi I am really new using R, so this is really a beginner stuff! I > created a very small data set on excel and then converted it to .csv > file. I am able to open the data on R using the command "read.table > ("mydata1.csv", sep=",", header=T)" and it just works fine. But when I > want to work on the data (e.g. calculate the mean of variable "X") R > says "object not found". I tried the "attach" command or "mean > ("mydata1.csv"&X)" but still I get the same error message. I don't > understand why R is having difficulty finding a variable. I believe I am doing something wrong. I will really appreciate if you could help me > with this. > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
What was the exact syntax? read.table> ("mydata1.csv", sep=",", header=T) will read the data but not save anything. mydat <-read.table ("mydata1.csv", sep=",", header=T) give you a data.frame called mydat. mean(mydat$X) should give you the mean of X John Kane Kingston ON Canada> -----Original Message----- > From: myjacaranda at yahoo.com > Sent: Tue, 15 May 2012 05:57:51 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] reading data into R > > Hi I am really new using R, so this is really a beginner stuff! I > created a very small data set on excel and then converted it to .csv > file. I am able to open the data on R using the command "read.table > ("mydata1.csv", sep=",", header=T)" and it just works fine. But when I > want to work on the data (e.g. calculate the mean of variable "X") R > says "object not found". I tried the "attach" command or "mean > ("mydata1.csv"&X)" but still I get the same error message. I don't > understand why R is having difficulty finding a variable. I believe I am > doing something wrong. I will really appreciate if you could help me > with this. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Hi ! You need to assign the output of read.table() into an object; this is how R works: mydata <- read.table ("mydata1.csv", sep=",", header=T) mymean <- mean(mydata$var) You should read some introductory material. I found this useful: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html And then, there are tons of good books and documentation (go check the CRAN as well) HTH, Ivan PS: post in plain text -- Ivan CALANDRA Universit? de Bourgogne UMR CNRS/uB 6282 Biog?osciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calandra at u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra Le 15/05/12 14:57, jacaranda tree a ?crit :> Hi I am really new using R, so this is really a beginner stuff! I > created a very small data set on excel and then converted it to .csv > file. I am able to open the data on R using the command "read.table > ("mydata1.csv", sep=",", header=T)" and it just works fine. But when I > want to work on the data (e.g. calculate the mean of variable "X") R > says "object not found". I tried the "attach" command or "mean > ("mydata1.csv"&X)" but still I get the same error message. I don't > understand why R is having difficulty finding a variable. I believe I am doing something wrong. I will really appreciate if you could help me > with this. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >