[R] cluster non-diet, diet example.

2007-02-09 Thread jia ding
Suppose, we have 3 people called: Francis, Cedric and Nina. Base on what
they have eaten, we want to cluster people by diet, non-diet.

# original data file, named as filename food.csv.
Francis|potato
Francis|chocolate
Francis|chocolate
Francis|milk
Cedric|vegetable
Cedric|vegetable
Cedric|potato
Nina|potato
Nina|chocolate
Nina|chocolate
Nina|potato

# Step 1: I plan to reform the food.csv file into following frame:
FrancisCedricNina
potato112
chocolate202
milk1000
fish0100
vegetable020

But, I have problem to reform the original file into that way I want.
Basically, I have only tried:
 org-read.table(food.csv,col.name=c(name,food_list), sep=|) #
import file to R
 x-data.frame(Francis=rep(0,times=5))# set up the frame of file
 rownames(x)-org$food_list
here I failed, and don't know how to continue.
Please help me out with the proper R command.

# Step 2: I want to draw 3 overlapped barplot with x-axis(5 food name list),
y-axis(the occurence value of each food by each person).

# Step 3: By comparing the barplots, I should be able to draw the
conclusion: Francis and Nina are in the group of non-diet, and Cedric is
in the group of diet.

Well, that's my simple strategy of clustering, if any of you have better
suggestion, I really appreciate it.

Thanks!

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


[R] merge files after cor.test

2006-09-04 Thread jia ding
Dear All,

Suppose I have 2 files:
# first one : testid.csv
A
B
C
D
E

 (id- read.table (testid.csv,col.name=c(id)))
  id
1  A
2  B
3  C
4  D
5  E

# second file is the result file I calculate from cor.text, which shows the
correlation coefficient.
 cor.value.t
  1  2   3   4  5
1 1.000  0.2156213  0.31000492  0.22282154  0.1822277
2 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
3 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
4 0.2228215  0.4268149 -0.02801885  1.  0.1454049
5 0.1822277  0.3421535 -0.13077317  0.14540493  1.000

# I tried to merge these two files together.
# what I expected is like this:
A 1.000  0.2156213  0.31000492  0.22282154  0.1822277
B 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
C 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
D 0.2228215  0.4268149 -0.02801885  1.  0.1454049
E 0.1822277  0.3421535 -0.13077317  0.14540493  1.000


# but after I used (output-merge(id,cor.value.t)), which shows 25 lines
(below):
   id 1  2   3   4  5
1   A 1.000  0.2156213  0.31000492  0.22282154  0.1822277
2   B 1.000  0.2156213  0.31000492  0.22282154  0.1822277
3   C 1.000  0.2156213  0.31000492  0.22282154  0.1822277
4   D 1.000  0.2156213  0.31000492  0.22282154  0.1822277
5   E 1.000  0.2156213  0.31000492  0.22282154  0.1822277
6   A 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
7   B 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
8   C 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
9   D 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
10  E 0.2156213  1.000 -0.31183893  0.42681488  0.3421535
11  A 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
12  B 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
13  C 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
14  D 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
15  E 0.3100049 -0.3118389  1. -0.02801885 -0.1307732
16  A 0.2228215  0.4268149 -0.02801885  1.  0.1454049
17  B 0.2228215  0.4268149 -0.02801885  1.  0.1454049
18  C 0.2228215  0.4268149 -0.02801885  1.  0.1454049
19  D 0.2228215  0.4268149 -0.02801885  1.  0.1454049
20  E 0.2228215  0.4268149 -0.02801885  1.  0.1454049
21  A 0.1822277  0.3421535 -0.13077317  0.14540493  1.000
22  B 0.1822277  0.3421535 -0.13077317  0.14540493  1.000
23  C 0.1822277  0.3421535 -0.13077317  0.14540493  1.000
24  D 0.1822277  0.3421535 -0.13077317  0.14540493  1.000
25  E 0.1822277  0.3421535 -0.13077317  0.14540493  1.000


Is anybody know why it outputs 5 times?

Thanks a lot!

Nina

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


[R] how can i see all the .Rdata files within R

2006-03-17 Thread jia ding
For example, I saved several .Rdata files with different names:
a.Rdata, b.Rdata ...  But, if I forget the specific file name, how can
I get all files list?

One more question about .R file:

 source(~/Desktop/allchapters.R,local=FALSE)
Error in parse(file, n = -1, NULL, ?) : syntax error at
135: names(airquality)
136: [

why?



Nina

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


Re: [R] how can i see all the .Rdata files within R

2006-03-17 Thread jia ding
On 3/17/06, jia ding [EMAIL PROTECTED] wrote:
 For example, I saved several .Rdata files with different names:
 a.Rdata, b.Rdata ...  But, if I forget the specific file name, how can
 I get all files list?

 One more question about .R file:

  source(~/Desktop/allchapters.R,local=FALSE)
 Error in parse(file, n = -1, NULL, ?) : syntax error at
 135: names(airquality)
 136: [



And I tried:
 load(~/Desktop/allchapters.R)
Error: bad restore file magic number (file may be corrupted) -- no data loaded

another error msg, I can not find explaination.




 why?



 Nina


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


Re: [R] Question about 'lables' ect.

2006-03-16 Thread jia ding
Thanks Marc  Liaw!

On 3/15/06, Marc Schwartz (via MN) [EMAIL PROTECTED] wrote:

 On Wed, 2006-03-15 at 17:54 +0100, jia ding wrote:
  Hi,
 
  I have a file named:
  test_R.txt
  aaa  2
  bbb  5
  ccc  7
  sss  3
  xxx  8
 
  I want to have a plot:
  test-read.table(test_R.txt,col.name=c(Name,Score))

  par(mfrow=c(1,2))

 It's not clear what the purpose is here, at least in this example. Do
 you plan on creating a second plot?


Yes, I want to plot the second one.
e.g. the second file is :
test2_R.txt
zszs  2
gjie  4
gjai  5
opwn  6
jgio  3
gjwn  8
owln  6
aonl  1
gols  7

I post the complete command here:

test-read.table(/vol/fpsearch/jiading/berman/single/test_R.txt,col.name=c
(Name,Score))
#single-single[order(-single$Weights),]   
#decreastest_R.txt,col.name=c(Name,Score))

test2-read.table(/vol/fpsearch/jiading/berman/single/test2_R.txt,
col.name=c(Name,Score))
par(mfrow=c(2,1))
t-barplot(test$Score,space=0.5)
axis(1,at=t,labels=as.character (test$Name))
t2-barplot(test2$Score,space=0.5)
axis(1,at=t2,labels=as.character(test2$Name))

P1; The problem is, even I set each plot with space=0.5, the bar's width
are different. The first plot's bars are lot wider than the second plot's.
What I want is, to make 2 plots same width.

 barplot(test$Score)
  name-test$Name
  axis(1,at=1:length(test$Name),labels=paste(name))
 
  Q1, if you try the script above,you will get 5 bars, the axis only shows
  aaa, ccc,xxx, but where are bbbsss?

 The easiest way to do this is to use the ' names.arg' argument in
 barplot():

 barplot(test$Score, names.arg = as.character(test$Name))


P2:  if I made 2 barplot next to each other by: par(mfrow=c(1,2)).  It seems
 names.arg doesn't work for the second plot ( test2_R.txt), as it
automatically hides some of the labels. Of course, in order to draw
everything, I can try to rotate the labels e.g. par(las=2).  While, I am
thinking, it should have some solution to solve this problem without turning
labels.

P3: if I typed pdf(test.pdf)
Suppose the plot has lots of bars.  Sometimes,there is not enough space for
pdf to draw everything. Which means it's not a complete file. Do you have
any suggestion about it?

PS: do you know, if there is the website which provides all the questions
people are asking now?  I mean,  when I  have problems I send email to
r-help@stat.math.ethz.ch, and then some nice people will have a look of my
problems and send me back their solutions. I am puzzled, except daily
R-help-request mail, how can I get other people's r-help mail simultaneous?
I remember I do subscribe to the mail group.

Thanks!

Nina



Note that the 'Name' column in the 'test' data frame will be a factor by
 default, so you need to convert it to a character vector here.

  Q2, pls have a look this x-axis again, you will find the middle of the
 bars
  are not pointing to the x-axes.

 Note that in the Value section of ?barplot, it indicates that barplot()
 returns the bar midpoints, which are not at integer values along the x
 axis.

 You would need to do something like:

 mp - barplot(test$Score)

 axis(1, at = mp, labels = as.character(test$Name))


  Q3, how can i change the width of the bars? I feel they are too fat.

 You can use the 'space' argument:

 barplot(test$Score, names.arg = as.character(test$Name), space = 0.5)


 See the descriptions of the 'width' and 'space' arguments in ?barplot
 for some of the subtleties here.

 See ?barplot for more information and further examples.

 HTH,

 Marc Schwartz




[[alternative HTML version deleted]]

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


[R] Question about 'lables' ect.

2006-03-15 Thread jia ding
Hi,

I have a file named:
test_R.txt
aaa  2
bbb  5
ccc  7
sss  3
xxx  8

I want to have a plot:
test-read.table(test_R.txt,col.name=c(Name,Score))
par(mfrow=c(1,2))
barplot(test$Score)
name-test$Name
axis(1,at=1:length(test$Name),labels=paste(name))

Q1, if you try the script above,you will get 5 bars, the axis only shows
aaa, ccc,xxx, but where are bbbsss?

Q2, pls have a look this x-axis again, you will find the middle of the bars
are not pointing to the x-axes.

Q3, how can i change the width of the bars? I feel they are too fat.

Thanks!
Nina

[[alternative HTML version deleted]]

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


Re: [R] 2 barplots in the same graph

2006-02-24 Thread jia ding
Thanks All!

I combine your answers and post the code here again, if later somebody need
it.

Actually, what I want is:
 x1
[1]  1  2 10
 x2
[1] -3  5 -8
 barplot(x1,col=white,border=red)
 barplot(x2,col=white,border=green,add=T)
So that, the two plots even share the same x-axis.

But, It comes another question: 
barplot(x2,col=white,border=green,add=T), because there are 2 numbers
are negative, some part of the bar is missing. Is there any automatic
function to make the axes fit very well for both bars?

And, suppose I want to add another command: axis(1, 0:20) to draw x-axis. I
notice it  increase like: 0,1,2,3,...20; how can I make it 0,5,15,20?

Thanks!


On 2/22/06, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 The barplot solution already presented is probably what you want
 but just in case here is a zoo solution:

 library(zoo)
 z - merge(zoo(x2), zoo(x1, seq(x1)+.5))
 plot(z, type = h, plot.type = single, col = 1:2, lwd = 5)

 Or a similar solution without zoo:
 plot(c(x1, x2) ~ c(seq(x1)+.5, seq(x2)),
   col = c(1+0*x1, 2+0*x2), type = h, lwd = 5)


 On 2/22/06, jia ding [EMAIL PROTECTED] wrote:
  Hello,
 
  I have a very simple question about 2 barplots in the same graph.
 
  It seems quite easy, but I searched google for long time, haven't find
  solution.
 
  For example, I want one graph like:
  x1=seq(0,2,by=0.3)
  x2=seq(3,0,by=-0.1)
  barplot(x1,col=red)
  barplot(x2,col=green)
 
  It means if it's on the same graph, some bars are overlaped.
  So if the bars are hollow, instead of filled with color, it will be
 better.
 
  Actually, I think it's something similar with matlab's hold on
 command.
 
  Thanks!
 
  Nina
 
 [[alternative HTML version deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 


[[alternative HTML version deleted]]

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


Re: [R] 2 barplots in the same graph

2006-02-24 Thread jia ding
Hi,
Would you pls try  these?

 x1-c(1,2,10)
 x2-c(-3,5,-8)
 barplot(x1,col=white,border=red,ylim=range(c(x1,x2)))
 barplot(x2,col=white,border=green,ylim=range(c(x1,x2)),add=T)
 axis(1, 0:3)
 box()


Q1, on x-axis 1,2,3 is not shown at the middle position of the bars.
e.gfor first bar, 1 is tend to right ; while third bar, 3 is tend
to left.
Q2, once box(), then bars are cut again.
Q3, when y-axis is 0, I want to draw a parallel line to  x-axis:
  I tried lines(c(0,5),c(0,0)) ; is there any other way to do it?

Thanks.

Nina




On 2/24/06, Romain Francois [EMAIL PROTECTED] wrote:

 Le 24.02.2006 11:17, jia ding a écrit :
  Thanks All!
 
  I combine your answers and post the code here again, if later somebody
 need
  it.
 
  Actually, what I want is:
 
  x1
 
  [1]  1  2 10
 
  x2
 
  [1] -3  5 -8
 
  barplot(x1,col=white,border=red)
  barplot(x2,col=white,border=green,add=T)


  So that, the two plots even share the same x-axis.
 
  But, It comes another question: 
  barplot(x2,col=white,border=green,add=T), because there are 2
 numbers
  are negative, some part of the bar is missing. Is there any automatic
  function to make the axes fit very well for both bars?
 
 
 R barplot(x1,col=white,border=red, ylim=range(c(x1,x2)))
  And, suppose I want to add another command: axis(1, 0:20) to draw
 x-axis. I
  notice it  increase like: 0,1,2,3,...20; how can I make it 0,5,15,20?
 
 
 before doing axis(1, 0:20) have you tried to do
 R 0:20

 So,

 R axis(1, (0:4)*5)
 or
 R axis(1, c(0,5, 10, 15, 20))
 or
 R axis(1, seq(0,20, by=5))

 it's up to you. There are probably other solutions as well
  Thanks!
 
 
 You're welcome

 Romain

 --
 visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
 Discover the R Movies Gallery : http://addictedtor.free.fr/movies
 +---+
 | Romain FRANCOIS - http://francoisromain.free.fr   |
 | Doctorant INRIA Futurs / EDF  |
 +---+



[[alternative HTML version deleted]]

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

[R] 2 barplots in the same graph

2006-02-22 Thread jia ding
Hello,

I have a very simple question about 2 barplots in the same graph.

It seems quite easy, but I searched google for long time, haven't find
solution.

For example, I want one graph like:
x1=seq(0,2,by=0.3)
x2=seq(3,0,by=-0.1)
barplot(x1,col=red)
barplot(x2,col=green)

It means if it's on the same graph, some bars are overlaped.
So if the bars are hollow, instead of filled with color, it will be better.

Actually, I think it's something similar with matlab's hold on command.

Thanks!

Nina

[[alternative HTML version deleted]]

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


[R] help-ERROR: unknown GUI none from Statistics::R

2006-02-21 Thread jia ding
Hi,

I download Statistics::R from
http://search.cpan.org/~gmpassos/Statistics-R-0.02/
I am going to combine R with perl.

but it keeps give the error msg: ERROR: unknown GUI none  stop running
script. I feel very strange, because previously it works.

my perl version is 5.8.6
my R version is Version 2.2.1

Is there anybody know about it?

Thanks a lot.

Nina

[[alternative HTML version deleted]]

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


[R] histogram error: 'x' must be numeric

2006-02-10 Thread jia ding
Hi All,

I have problem to plot histogram.

What I did is:

export a .csv file from PSQL database's table.
so, inside this .csv file it looks like:
31.845
24.598
29.1223
24.715
23.1847
24.2321
25.2995
23.4261
30.7873
..

Then, I use command:
score- read.csv('file.csv', header = FALSE,sep = ,)
hist(score, main = score)

it gives error msg:
Error in hist.default(score, main = score) :
'x' must be numeric

Can any of you know about it explain me why?

Thanks a lot.

Nina

[[alternative HTML version deleted]]

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


[R] library(lattice)

2005-11-09 Thread jia ding
I first try these command, it works quite well.
library(lattice)
data(cuckoos)
levnam - strsplit(levels(cuckoos$species), \\.)

BUT, i want to try :
levnam - strsplit(levels(cuckoos$species), .)
to see the difference.

They maybe I modified the data file, because when I try again, it says:
 data(cuckoos)
Warning message:
data set 'cuckoos' not found in: data(cuckoos)

would you please tell me how to deal with this problem?
I have already tried update.packages()
it doesn't help.

Thanks.
DJ

[[alternative HTML version deleted]]

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


[R] accident modified dataset. How can I recovery it?!

2005-11-09 Thread jia ding
I first try these command, it works quite well.
library(lattice)
data(cuckoos)
levnam - strsplit(levels(cuckoos$species), \\.)

BUT, i want to try :
levnam - strsplit(levels(cuckoos$species), .)
to see the difference.

They maybe I modified the data file, because when I try again, it says:
 data(cuckoos)
Warning message:
data set 'cuckoos' not found in: data(cuckoos)

would you please tell me how to deal with this problem?
I have already tried update.packages()
it doesn't help.

Thanks.
DJ

[[alternative HTML version deleted]]

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


Re: [R] accident modified dataset. How can I recovery it?!

2005-11-09 Thread jia ding
I tried to reinstall the package. but my R version is too old.

[EMAIL PROTECTED]:~$ sudo R CMD INSTALL -l /usr/lib/R/library
/home/dj/Desktop/lattice_0.12-11.tar.gz
Password:
ERROR: This R is version 2.1.1
package 'lattice' needs R = 2.2.0

So, *my question being, how do I upgrade from R version *R = 2.2.0
* to R *2.1.1* and keep all of my libraries intact? *


On 11/9/05, jia ding [EMAIL PROTECTED] wrote:

 I first try these command, it works quite well.
 library(lattice)
 data(cuckoos)
 levnam - strsplit(levels(cuckoos$species), \\.)

 BUT, i want to try :
 levnam - strsplit(levels(cuckoos$species), .)

 to see the difference.

 They maybe I modified the data file, because when I try again, it says:
  data(cuckoos)
 Warning message:
 data set 'cuckoos' not found in: data(cuckoos)

 would you please tell me how to deal with this problem?

 I have already tried update.packages()
 it doesn't help.

 Thanks.
 DJ



[[alternative HTML version deleted]]

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


[R] question about R graphics-example plot attached

2005-11-08 Thread jia ding
-- Forwarded message --
From: jia ding [EMAIL PROTECTED]
Date: Nov 2, 2005 4:03 PM
Subject: question about R graphics-example plot attached
To: [EMAIL PROTECTED]

Suppose I have the data set like this:
A 1
3
7
10

B 5
9
13
The numbers here actually is A or B's occurence positions.So it means,
position 1,3,7,10 is A;position 5,9,13 is B's occurence.

I want the plot is a line with a little dot (or bar) at the position
1(A-show red), position 3(A-red),position
5(B-blue),7(A-red),10(A-red),13(B-blue)

I am not sure, If I explained very clearly about my question. What a
pity google group not support to attach a file. Otherwise,I can provide
an example.

Thanks for the help!
Thanks Marc.
 DJ


output.png
Description: PNG image
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html