An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120515/8065fe79/attachment.pl>
reading data into R
4 messages · jacaranda tree, R. Michael Weylandt, John Kane +1 more
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.