[R] Excel files

Robert W. Baer, Ph.D. rbaer at atsu.edu
Mon Mar 8 02:43:49 CET 2004


This might get you started on reading and plotting the dates and times for
levels of a gender factor:
# I assume the following Excel data
date time Sex Value
1 5/5/1999 10:00:00 male 14.987685
2 7/3/1998 20:00:00 female 17.667527
3 8/6/1999 3:23:00 male 3.428401
4 12/7/1997 6:36:00 male 14.977503
5 3/4/2004 9:49:00 male 6.704703
6 11/15/1999 23:04:00 female 5.536046
7 10/16/1998 6:05:00 male 12.153291
8 2/5/1999 3:06:00 female 12.121168
9 3/3/1997 3:07:00 male 4.641686
10 8/6/2004 7:08:00 male 6.649273
11 8/7/1999 22:10:00 male 11.158278
12 7/4/1998 21:11:00 female 8.098113
13 7/6/1999 5:15:00 male 6.220476
14 9/1/1997 6:16:00 female 1.939658
15 3/15/2004 7:05:00 male 2.032969
16 5/16/1999 2:23:00 male 16.436000
#Simulate Excel read
x<-read.table("clipboard")
x

# Do your plotting
library(chron)
timedate=chron(as.character(x$date),as.character(x$time),format=c(dates="m/d
/y",times="h:m:s"))
plot(x$Value~timedate,pch=as.numeric(x$Sex))

1. How can I access the data of certain column? I mean how can I refer it in
R?
Notice how the read in data is in a dataframe.  To access a given column of
the data frame use a $ plus the column name.
2. How can I make the two column character values(the time variable I
mentioned) to the X ases values?
see the construction of timedate
3. If I have three variables, one is y axes, one is x axes,  the third one
is a logic var, how can I make the logic varaible on the plot also?
I don't know precisely what you want but see how I show gender using the
pch= tag to get different plot symbols.  The details depend what you want
here.


HTH,

Rob Baer
----- Original Message ----- 
From: "Grace Conlon" <gracestat at yahoo.com>
To: <R-help at stat.math.ethz.ch>
Sent: Sunday, March 07, 2004 5:43 PM
Subject: [R] Excel files


Hello,

I was trying to import data from an Excel file. After I imported the data, I
was trying to make a scatter plot.

The X axes variable is a time variable, which occupies two columns, one is
date, another one is time. Example 21-Apr-03, 4:10 PM.   My qestion is:


4. I have a column of number values, however I want to creat a new column,
the value of each cell is the average of every 10 values of the first
column. How can I do it in R?

I tried to figure it out in the help section, however, it spent me a lot of
times, I still can not get the way out, please help. THank you!



---------------------------------


[[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list