Re: [R] readLines errors

2011-12-24 Thread rusers.sh
Hi All,
  I just tried Firefox that David referred and found it can also return the
correct result as Google Chrome.
 So now it is more clear now that readLines() function uses IE as the
default explorer, so it return the wrong result. Then the possible
solutions are,
1. Could we change the options in readLines() to set another  explorer as
the default explore, e.g. Google Chrome?
2. Could it be possible to set IE explorer in a rational way, so that it
can return the same results as Google Chrome  and Firefox? I have tried to
modify the encoding method in IE, but it doesnot work.
  Any suggestions or help?

ÔÚ 2011Äê12ÔÂ24ÈÕ ÏÂÎç5:12£¬rusers.sh дµÀ£º

> Hi All,
>   I met a problem using readLines function to return the data from Google
> maps.
>
>   readLines(url("
> http://ditu.google.cn/maps/geo?q=+qianshuichong,+guichi+anhui,+CN&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg";),
> n=1, warn=FALSE)
>
> [1] "200,4,30.6528380,117.4872250"
>
>   The above code is ok because the address is English, but it cannot work
> when i change the address into zh-hans (Chinese simplified). See below.
>
>   
> readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN®ion=zh_Hans"),
> n=1, warn=FALSE)
>
> [1] "400,0,0,0"
>
>   The returned value is wrong. I also tried several other options, but
> still have the same problem. The interesting thing is if i paste the URL
> into the IE explorer directly, it do return the correct values.
>
>   Anybody can give me some suggestions or hints to solve this?
>
>   Thanks a lot.
>
>  P.S. See below for the other possibilities i tried.
>
> readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN®ion=zh"),
> n=1, warn=FALSE)
>
> [1] "400,0,0,0"
>
> readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN"),
> n=1, warn=FALSE)
>
> [1] "400,0,0,0"
>
> readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN"),
> n=1, warn=FALSE,encoding="UTF-8")
>
> [1] "400,0,0,0"
>
>
> --
> -
> Jane Chang
> Queen's
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] readLines errors

2011-12-24 Thread rusers.sh
  I just found another strange thing. When i paste the URL into the Google
Chrome, i can get the correct result "200,4,30.5892200,117.4286680". But i
paste it into the IE explorer, the result is wrong "400,0,0,0".
  I guess that the R uses the IE as default. Could i tell R to use  Google
Chrome as a default explorer? Or how can i find the possible solution for
IE to return the same result as  Google Chrome .
 Confusing.

2011/12/24 David Winsemius 

>
> On Dec 24, 2011, at 4:12 AM, rusers.sh wrote:
>
>  Hi All,
>>  I met a problem using readLines function to return the data from Google
>> maps.
>>
>>  readLines(url("
>> http://ditu.google.cn/maps/**geo?q=+qianshuichong,+guichi+**
>> anhui,+CN&output=csv&key=**ABQIq8Fnd_oUka-**
>> 7RdS6BrD7GBTqeABoQuNTXS36G_**rkiwQnKRW6GBTkns8JpKz6y6dScgB8**827dlddUlg<http://ditu.google.cn/maps/geo?q=+qianshuichong,+guichi+anhui,+CN&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg>
>> "),
>> n=1, warn=FALSE)
>>
>> [1] "200,4,30.6528380,117.4872250"
>>
>>  The above code is ok because the address is English, but it cannot work
>> when i change the address into zh-hans (Chinese simplified). See below.
>>
>>  
>> readLines(url("http://ditu.**google.cn/maps/geo?q=+Ç<http://ditu.google.cn/maps/geo?q=+%C3%87>
>> °Ë®³åhttp://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
>> **>
>> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&**key=ABQIq8Fnd_oUka-**
>> 7RdS6BrD7GBTqeABoQuNTXS36G_**rkiwQnKRW6GBTkns8JpKz6y6dScgB8**
>> 827dlddUlg&language=zh-CN&**region=zh_Hans"),
>> n=1, warn=FALSE)
>>
>
> When I plug that URL into my browser (Firefox) I get this text on a white
> background:
>
> 602,0,0,0
> When I execute that code in R I get:
> [1] "{"
> And when I remove the lines restriction I get:
> [1] "{"
> [2] "  \"name\": \" 
> Ç°Ë®³å\\u003chttp://ditu.**google.cn/maps/geo?q=<http://ditu.google.cn/maps/geo?q=>前水冲\\u003e\","
> [3] "  \"Status\": {"
> [4] "\"code\": 602,"
> [5] "\"request\": \"geocode\""
> [6] "  }"
> [7] "}"
> I don't read Chinese , however it does appear that there was some sort of
> extra processing step that Firefox carried out to arrive at the displayed
> text.
>
>
>> [1] "400,0,0,0"
>>
>>  The returned value is wrong. I also tried several other options, but
>> still have the same problem. The interesting thing is if i paste the URL
>> into the IE explorer directly, it do return the correct values.
>>
>>  Anybody can give me some suggestions or hints to solve this?
>>
>>  Thanks a lot.
>>
>> P.S. See below for the other possibilities i tried.
>>
>> readLines(url("http://ditu.**google.cn/maps/geo?q=+Ç<http://ditu.google.cn/maps/geo?q=+%C3%87>
>> °Ë®³åhttp://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
>> **>
>> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&**key=ABQIq8Fnd_oUka-**
>> 7RdS6BrD7GBTqeABoQuNTXS36G_**rkiwQnKRW6GBTkns8JpKz6y6dScgB8**
>> 827dlddUlg&language=zh-CN&**region=zh"),
>> n=1, warn=FALSE)
>>
>> [1] "400,0,0,0"
>>
>> readLines(url("http://ditu.**google.cn/maps/geo?q=+Ç<http://ditu.google.cn/maps/geo?q=+%C3%87>
>> °Ë®³åhttp://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
>> **>
>> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&**key=ABQIq8Fnd_oUka-**
>> 7RdS6BrD7GBTqeABoQuNTXS36G_**rkiwQnKRW6GBTkns8JpKz6y6dScgB8**
>> 827dlddUlg&language=zh-CN"),
>> n=1, warn=FALSE)
>>
>> [1] "400,0,0,0"
>>
>> readLines(url("http://ditu.**google.cn/maps/geo?q=+Ç<http://ditu.google.cn/maps/geo?q=+%C3%87>
>> °Ë®³åhttp://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2>
>> **>
>> ,+¹ó³Ø+°²»Õ,+Öйú&output=csv&**key=ABQIq8Fnd_oUka-**
>> 7RdS6BrD7GBTqeABoQuNTXS36G_**rkiwQnKRW6GBTkns8JpKz6y6dScgB8**
>> 827dlddUlg&language=zh-CN"),
>>
>> n=1, warn=FALSE,encoding="UTF-8")
>>
>> [1] "400,0,0,0"
>>
>>
>> --
>> -
>> Jane Chang
>> Queen's
>>
>>[[alternative HTML version deleted]]
>>
>> __**
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] readLines errors

2011-12-24 Thread rusers.sh
Hi All,
  I met a problem using readLines function to return the data from Google
maps.

  readLines(url("
http://ditu.google.cn/maps/geo?q=+qianshuichong,+guichi+anhui,+CN&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg";),
n=1, warn=FALSE)

[1] "200,4,30.6528380,117.4872250"

  The above code is ok because the address is English, but it cannot work
when i change the address into zh-hans (Chinese simplified). See below.

  
readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å
,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN®ion=zh_Hans"),
n=1, warn=FALSE)

[1] "400,0,0,0"

  The returned value is wrong. I also tried several other options, but
still have the same problem. The interesting thing is if i paste the URL
into the IE explorer directly, it do return the correct values.

  Anybody can give me some suggestions or hints to solve this?

  Thanks a lot.

 P.S. See below for the other possibilities i tried.

readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å
,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN®ion=zh"),
n=1, warn=FALSE)

[1] "400,0,0,0"

readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å
,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN"),
n=1, warn=FALSE)

[1] "400,0,0,0"

readLines(url("http://ditu.google.cn/maps/geo?q=+Ç°Ë®³å
,+¹ó³Ø+°²»Õ,+Öйú&output=csv&key=ABQIq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg&language=zh-CN"),
n=1, warn=FALSE,encoding="UTF-8")

[1] "400,0,0,0"


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] obtain coordinates in google earth

2011-12-20 Thread rusers.sh
Hi all,
  Anybody has ever used R to automatically search  the coordinates in GE? I
searched the website, but cannot find some useful information.
  My addresses are not very regular, so the methods that require the strict
address formats may be not good.
  Say my address is "kingston ontario canada". But putting it in GE, the
results is "44D13M52.22S N 76D29M09.43S W elevation 257ft".
The problem is i have many addresses like this, so an automatic method is
better.
  Any suggestions or ideas on this?

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] use same breaks and colors, but the displayed scale are different-image.plot()

2010-09-16 Thread rusers.sh
Thanks guys. I forgot to use the argument "zlim". It's solved.

2010/9/16 Jim Lemon 

> On 09/16/2010 12:05 PM, rusers.sh wrote:
>
>> Hi all,
>>   I want to put several figures in a one figure for easy comparison, so i
>> need to use the same methods to plot these figures. The following is an
>> example. I also list my method, but it does not work.
>> #Example data
>> x<- 1:10; y<- 1:10; z<- outer( x,y,"+");z2<- outer( x,y,"-")
>> #Quick view them
>> image.plot(x,y,z)  #relatively larger value
>> image.plot(x,y,z2)   #relatively small value
>> #define the same breaks and colors
>> brks<-quantile(c(as.vector(z),as.vector(z2)),na.rm=TRUE)
>> colsn<-length(brks)-1
>> cols<-gray((colsn:1)/colsn)
>> #I expect they use the same breaks and colors
>> par(mfrow=c(1,2))
>> image.plot(x,y,z,breaks=brks,col=cols)
>> image.plot(x,y,z2,breaks=brks,col=cols)
>> par(mfrow=c(1,1))
>>   I think they really use the same breaks and colors, but you can see the
>> color legends are still different. One is 20-15-10-5, another is 5-0--5.
>>   I hope they not only use the same breaks and colors, but also display
>> the
>> same color legends. How can i do it?
>>
>
> Hi Jane,
> The color.legend function in the plotrix package will do this - see the
> examples, especially those for the "barp" function.
>
> Jim
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] use same breaks and colors, but the displayed scale are different-image.plot()

2010-09-15 Thread rusers.sh
Hi all,
  I want to put several figures in a one figure for easy comparison, so i
need to use the same methods to plot these figures. The following is an
example. I also list my method, but it does not work.
#Example data
x<- 1:10; y<- 1:10; z<- outer( x,y,"+");z2<- outer( x,y,"-")
#Quick view them
image.plot(x,y,z)  #relatively larger value
image.plot(x,y,z2)   #relatively small value
#define the same breaks and colors
brks<-quantile(c(as.vector(z),as.vector(z2)),na.rm=TRUE)
colsn<-length(brks)-1
cols<-gray((colsn:1)/colsn)
#I expect they use the same breaks and colors
par(mfrow=c(1,2))
image.plot(x,y,z,breaks=brks,col=cols)
image.plot(x,y,z2,breaks=brks,col=cols)
par(mfrow=c(1,1))
  I think they really use the same breaks and colors, but you can see the
color legends are still different. One is 20-15-10-5, another is 5-0--5.
  I hope they not only use the same breaks and colors, but also display the
same color legends. How can i do it?
  Any suggestions or help are appreciate.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] cannot allocate vector of size 381.5 Mb

2010-08-30 Thread rusers.sh
Hi,
  I read some posts from the mailing list on the same problem, but it seems
that i still cannot solve this problem.
I only want to generate some simulated data.
#Generate 2500 observations-it works without errors
> coords<-as.matrix(expand.grid(seq(0,100,length.out=50),
seq(0,100,length.out=50)))
#SimData is a user-written function
> SimBinData<-SimData(n=2500,coords=coords, 
> x.mu=c(0,1),covar.cor=matrix(c(1,0.25,0.25,1),
2, 2),beta=c(1,0.5,5))
#Generate 1 observations-errors appeared
#Following some posts, i set the memory to the maximum value. But i still
got errors.
> memory.limit(size = 4095)
[1] 4095
> coords<-as.matrix(expand.grid(seq(0,100,length.out=100),
seq(0,100,length.out=100)))
> SimBinData<-SimData(n=1,coords=coords, 
> x.mu=c(0,1),covar.cor=matrix(c(1,0.25,0.25,1),
2, 2),beta=c(1,0.5,5))
Error: cannot allocate vector of size 381.5 Mb
> memory.size(TRUE)
[1] 1276.31
> memory.limit()
[1] 4095
> object.size(SimBinData)
170568 bytes
  Any suggestions?
  Thanks very much.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] generate random numbers from a multivariate distribution with specified correlation matrix

2010-08-24 Thread rusers.sh
BTW, can you recommend a book on statistical simulations? I want to know
more on how to generate random numbers from distributions, how to generate
the theoretical models,...
Thanks a lot.

2010/8/24 Michael Dewey 

> At 02:40 24/08/2010, rusers.sh wrote:
>
>> Hi all,
>>  rmvnorm()can be used to generate the random numbers from a multivariate
>> normal distribution with specified means and covariance matrix, but i want
>> to specify the correlation matrix instead of covariance matrix for the
>> multivariate
>> normal distribution.
>>
>
> Jane, perhaps I misunderstand you but the correlation matrix is a
> covariance matrix
>
>
>  Does anybody know how to generate the random numbers from a multivariate
>> normal distribution with specified correlation matrix? What about
>> other non-normal
>> distribution?
>>
>
> There is corcounts for correlated count variables and a couple of packages
> for correlated binary variables, search the packages list for correlated for
> details. I have not used any of these so can offer no recommendations.
>
>  Thanks a lot.
>>
>> --
>> -
>> Jane Chang
>> Queen's
>>
>>[[alternative HTML version deleted]]
>>
>
> Michael Dewey
> m...@aghmed.fsnet.co.uk
> http://www.aghmed.fsnet.co.uk/home.html
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] generate random numbers from a multivariate distribution with specified correlation matrix

2010-08-24 Thread rusers.sh
Great. It is more clearer for me. Thanks all.

2010/8/24 Michael Dewey 

> At 02:40 24/08/2010, rusers.sh wrote:
>
>> Hi all,
>>  rmvnorm()can be used to generate the random numbers from a multivariate
>> normal distribution with specified means and covariance matrix, but i want
>> to specify the correlation matrix instead of covariance matrix for the
>> multivariate
>> normal distribution.
>>
>
> Jane, perhaps I misunderstand you but the correlation matrix is a
> covariance matrix
>
>
>  Does anybody know how to generate the random numbers from a multivariate
>> normal distribution with specified correlation matrix? What about
>> other non-normal
>> distribution?
>>
>
> There is corcounts for correlated count variables and a couple of packages
> for correlated binary variables, search the packages list for correlated for
> details. I have not used any of these so can offer no recommendations.
>
>  Thanks a lot.
>>
>> --
>> -
>> Jane Chang
>> Queen's
>>
>>[[alternative HTML version deleted]]
>>
>
> Michael Dewey
> m...@aghmed.fsnet.co.uk
> http://www.aghmed.fsnet.co.uk/home.html
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] generate random numbers from a multivariate distribution with specified correlation matrix

2010-08-23 Thread rusers.sh
Hi,
  If you see the link http://www.stata.com/help.cgi?drawnorm, and you can
see an example,
#draw a sample of 1000 observations from a bivariate standard
normal distribution, with correlation 0.5.
#drawnorm x y, n(1000) corr(0.5)
 This is what Stata software did. What i hope to do in R should be similar
as that.
  It will be better to only need us to specify the correlation matrix, mean
values and possible variances. One of my aim is to simulate random fields.
  Thanks.


2010/8/23 Ben Bolker 

> rusers.sh  gmail.com> writes:
>
> >   rmvnorm()can be used to generate the random numbers from a multivariate
> > normal distribution with specified means and covariance matrix, but i
> want
> > to specify the correlation matrix instead of covariance matrix for the
> > multivariate
> > normal distribution.
> > Does anybody know how to generate the random numbers from a multivariate
> > normal distribution with specified correlation matrix? What about
> > other non-normal
> > distribution?
>
>   What do you want the variances to be?  If you don't mind that they're
> all equal to 1, then using your correlation matrix as the Sigma argument
> to the mvrnorm() [sic] function in MASS should work fine.  They have to
> be defined as *something* 
>  If you want multivariate distributions with non-normal marginal
> distributions, consider the 'copula' package, but be prepared to do
> some reading -- this is a fairly big/deep topic.
>
>  good luck.
>
> __
> R-help@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.
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] generate random numbers from a multivariate distribution with specified correlation matrix

2010-08-23 Thread rusers.sh
Hi all,
  rmvnorm()can be used to generate the random numbers from a multivariate
normal distribution with specified means and covariance matrix, but i want
to specify the correlation matrix instead of covariance matrix for the
multivariate
normal distribution.
Does anybody know how to generate the random numbers from a multivariate
normal distribution with specified correlation matrix? What about
other non-normal
distribution?
Thanks a lot.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] problem of R CMD check

2010-04-22 Thread rusers.sh
eckExEnv")
options(contrasts = c(unordered = "contr.treatment", ordered =
"contr.poly"))
options(pager = "console")
library('sbar')

assign(".oldSearch", search(), pos = 'CheckExEnv')
assign(".oldNS", loadedNamespaces(), pos = 'CheckExEnv')
cleanEx(); nameEx("stKDE.simcomp")
### * stKDE.simcomp

flush(stderr()); flush(stdout())

### Name: stKDE.simcomp
### Here, just copied my example codes, so i ignored here to save space.

### * 
###
cat("Time elapsed: ", proc.time() - get("ptime", pos = 'CheckExEnv'),"\n")
grDevices::dev.off()
###
### Local variables: ***
### mode: outline-minor ***
### outline-regexp: "\\(> \\)?### [*]+" ***
### End: ***
quit('no')



2010/4/22 Dennis Murphy 

> Hi Jane,
>
> I was just hoping to save you some duplicate work, but it's probably safer
> to compile for both because the latest Revolution Computing free version
> is 2.10.1 and will probably stay that way for a while. Hopefully you don't
> need a new set of tools for 2.11, though. It's not that unusual for
> examples
> to crash in new installations; it's usually something subtle like a new
> feature
> or a bug fix in a program that may or may not be related to your code. Just
> ram the examples through a debugger.
>
> Have fun,
> Dennis
>
>
> On Wed, Apr 21, 2010 at 8:22 PM, rusers.sh  wrote:
>
>> Hi Dennis,
>>   I mean the V2.10.1. :-)
>> 2010/4/21 Dennis Murphy 
>>
>>> Hi Jane,
>>>
>>> The new version of R is coming out tomorrow, if you weren't already aware
>>> of that... :)
>>>
>>> HTH,
>>> Dennis
>>>
>>> On Wed, Apr 21, 2010 at 4:29 PM, rusers.sh  wrote:
>>>
>>>> Hi all,
>>>>Today, i just installed the newest R version 2.10.1 and other
>>>> necessary
>>>> tools for building R package under windows,e.g. Rtools, perl. All are
>>>> the
>>>> newest version.
>>>>  After the correct configuration under windows, i use it to re-check my
>>>> old
>>>> package. I found the following prolem when checking EXAMPLE, which did
>>>> not
>>>> exist before this re-installation.
>>>> 
>>>> * checking examples ... ERROR
>>>>  Running examples in 'stam-Ex.R' failed.
>>>> 
>>>>  I used "\dontrun{} % enddontrun" in all the examples that should be no
>>>> problem, i think. I checked my package before and did not find errors.
>>>>  Any ideas on this?
>>>>  Thanks a lot.
>>>>
>>>> --
>>>> -
>>>> Jane Chang
>>>> Queen's
>>>>
>>>>[[alternative HTML version deleted]]
>>>>
>>>> __
>>>> R-help@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.
>>>>
>>>
>>>
>>
>>
>> --
>> -
>> Jane Chang
>> Queen's
>>
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] problem of R CMD check

2010-04-21 Thread rusers.sh
Hi all,
Today, i just installed the newest R version 2.10.1 and other necessary
tools for building R package under windows,e.g. Rtools, perl. All are the
newest version.
  After the correct configuration under windows, i use it to re-check my old
package. I found the following prolem when checking EXAMPLE, which did not
exist before this re-installation.

* checking examples ... ERROR
 Running examples in 'stam-Ex.R' failed.

  I used "\dontrun{} % enddontrun" in all the examples that should be no
problem, i think. I checked my package before and did not find errors.
  Any ideas on this?
  Thanks a lot.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] selected observations based several variables

2010-04-07 Thread rusers.sh
Hi,
  My problem maybe a little bit complicated, so forgive me if the following
words are too much.
#date set
a0<-matrix(c(1.1,1.3,1.1,1.3,1.3, 2.0,1.8,2.0,1.8,1.8,
 "12/01/2008","05/20/2007","12/06/2008","05/10/2007","05/06/2007",
"N","N","A","C","A", 1,2,3,4,5),ncol=5,byrow=FALSE)
a0<-data.frame(a0); colnames(a0)<-c("x","y","date","prior","var5")
a0$date<-as.Date(a0$date,format="%m/%d/%Y")
> a0
x y   date   prior  var5
1 1.1   2 2008-12-01 N1
2 1.3 1.8 2007-05-20 N2
3 1.1   2 2008-12-06 A3
4 1.3 1.8 2007-05-10 C4
5 1.3 1.8 2007-05-06 A5
  I want to select the observations based on the values of x and y, but also
need to consider the values of "prior". The rough ideas are as follows.
# Check whether there are observations which have same x and y values,e.g.1
and 3. If same, their date difference need to be checked further. If their
date difference is <=8days, we only need to keep the earliest observarion;
#During this selection, variable of "prior" is also needed to be
considered. For "prior", the priority is C>A>N. For the same several
observations, if the earliest observation has a value of "N" and other later
observations have "A" or "C", then we also need to replace the earliest
observation's "N" into "C" or "A",which depends the priority C>A>N.
#If their date difference is >8days, donot need to conduct the above
manipulation. Keep them.
#And also keep all the other observations whose donot have the same x and y
values.
#So the final result should be
x   y   date prior var5
1 1.1   2 2008-12-01 A1
5 1.3 1.8 2007-05-06 C5
2 1.3 1.8 2007-05-20 N2
#obs1 and obs3 have same x and y; Their date difference is 5, so we will
select the earlist obs1 But we notice that its prior value is N, while
another is A, so we also need to replace N using A.
#obs2,obs4 and obs5 have same x and y; Obs4 and obs5 has a date difference
4<=8days,
so earlies obs 5 will be selected, but also we need to replace A using C
because of the priority.If the prior value for obs4 is N, then we donot need
to replace the A of obs5 because A is prior to N.

  I hope i have made it clear for this problem. It seems to be complex. If
the dataset is small, we can do it manually. But it will be impossible for a
large dataset. Anybody has some ideas on this?
  Any suggestions or help are appreciated.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Use a variable of a list in a loop

2010-04-07 Thread rusers.sh
Cool.
Using [[var]] instead of $var to extract the expected variable is really
what i want.
Thanks. Guys.

2010/4/7 Steve Lianoglou 

> Hi,
>
> On Wed, Apr 7, 2010 at 6:27 PM, rusers.sh  wrote:
> > Hi all,
> >  My problem may be related with the list manipulations. See below.
> > #example data
> >  a<-list()
> >  a[[1]]<-data.frame(matrix(c(1:4),ncol=2));
> > a[[2]]<-data.frame(matrix(c(5:8),ncol=2))
> >  I can use a[[1]]$X1,a[[1]]$X2,a[[2]]$X1,a[[2]]$X2 to use the
> corresponding
> > variables. But what i need to do is to use function parameters to specify
> > the variable names. The variable names will be different for various
> > dataset, so i need a common place to indicate it.
> >  Something like,
> > b<-function(var1=X1,var2=X2) {
> >  for (n in 1:2) {
> >  paste("a", "[[",n, "]]","$","var1", sep="")
> >  paste("a", "[[",n, "]]","$","var2", sep="")
> >  }
> > }
> >  b(var1=X1,var2=X2) will have the same effect
> > as a[[1]]$X1,a[[1]]$X2,a[[2]]$X1,a[[2]]$X2. Unfortunately, it does not
> > work.
> >  Anybody can give me some suggestions on this? Hope it is clear for this
> > question.
>
> I'm not really sure what you're trying to do, but if you just want to
> select out certain columns of a data.frame by passing the name of the
> column around in someway, pass its name as a string and select the
> collumn using [[var]] instead of $var.
>
> For instance, using your data.frame ``a``. Say I want to either pull
> out 'X1', or 'X2', you could do:
>
> R> some.column <- 'X1'
> R> a[[1]][[some.column]]
>
> So whatever you are trying to do in your b() function, maybe you would
> change it like so:
>
> b <- function(var1='X1', var2='X2') {
>  ## notice 'X1' and 'X2' are in quote in mine
>  ...
>  cat(a[[n]][[var1]], '\n')
> }
>
> Also -- your call to `paste` isn't doing what I think you think it's
> doing (what do you want it to do?)
>
> Does that get you closer to what you need?
>
> -steve
>
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Use a variable of a list in a loop

2010-04-07 Thread rusers.sh
Hi all,
  My problem may be related with the list manipulations. See below.
#example data
 a<-list()
 a[[1]]<-data.frame(matrix(c(1:4),ncol=2));
a[[2]]<-data.frame(matrix(c(5:8),ncol=2))
  I can use a[[1]]$X1,a[[1]]$X2,a[[2]]$X1,a[[2]]$X2 to use the corresponding
variables. But what i need to do is to use function parameters to specify
the variable names. The variable names will be different for various
dataset, so i need a common place to indicate it.
  Something like,
b<-function(var1=X1,var2=X2) {
 for (n in 1:2) {
  paste("a", "[[",n, "]]","$","var1", sep="")
  paste("a", "[[",n, "]]","$","var2", sep="")
  }
}
 b(var1=X1,var2=X2) will have the same effect
as a[[1]]$X1,a[[1]]$X2,a[[2]]$X1,a[[2]]$X2. Unfortunately, it does not
work.
 Anybody can give me some suggestions on this? Hope it is clear for this
question.
 Thanks a lot.
P.S.
> a
[[1]]
  X1 X2
1  1  3
2  2  4
[[2]]
  X1 X2
1  5  7
2  6  8


-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Error--memory could not be "read"

2010-03-14 Thread rusers.sh
Hi,
  I wrote my own function to finish my work. One strange thing happened. If
i set the number of simulations to be "10", it goes correctly. But if i set
the number of simulations into "100", then errors appeared.
 Error information: The instruction at "0x6abf12cf" referenced memory at
"0x0286fff8". The memory could not be "read".
  Anybody met the similar problem? How to avoid this?
  I appreciate your suggestions.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] split function

2010-02-26 Thread rusers.sh
Thanks.
I think i mistake the sampling() with split().

2010/2/26 David Winsemius 

>
> On Feb 26, 2010, at 2:40 PM, rusers.sh wrote:
>
>  Your method seems to only re-express the data "data.frame(x, g)" using
>> another format.
>>
>
> In all fairness to the first respondent to your question, that _was_ what
> it appeared you were requesting. My other thoughts would be:
>
> > cbind(x[order(g)], sort(as.numeric(as.character(g # g is a factor
> # so sort(g) or g[order(g)] returns the internal index.
>[,1] [,2]
>  [1,] -0.06782370
>  [2,]  2.25381490
>  [3,]  1.89512570
>  [4,]  2.20796200
>  [5,]  3.20112671
>  [6,] -0.55240361
>  [7,]  0.78917431
>  [8,]  2.25200061
>  [9,]  1.11914211
> [10,]  2.29234701
> [11,]  3.58316951
> [12,]  2.22990132
> [13,]  1.51407592
>
> or:
>
> >split(data.frame(x=x,g=g), g)
> > split(data.frame(x=x,g=g), g)
> $`0`
>x g
> 6  -0.0678237 0
> 15  2.2538149 0
> 18  1.8951257 0
> 30  2.2079620 0
>
> $`1`
>x g
> 1   3.2011267 1
> 3  -0.5524036 1
> 10  0.7891743 1
> 12  2.2520006 1
> 17  1.1191421 1
> 19  2.2923470 1
> 29  3.5831695 1
>
> $`2`
>   x g
> 2  2.2299013 2
> 
>
> Which also re-express it. But if that is not what you want then offer a
> better explanation  and a different example of desired output.
>
>
>
>  The results are really from the generated data frame. Maybe
>> be not good.
>>
>>> table(g)
>>>
>> g
>> 0 1 2 3
>> 7 9 8 6
>>  I hope to randomly split the value 'x' according to the different sample
>> sizes of different levels, displayed above. That is, 7 for level 0, 9 for
>> level 1, et al.
>>  Thanks.
>>
>
> Or maybe you don't want the value of x but the number of elements?
>
> > tapply(x, g, length)  # another way to get a table
>  0  1  2  3 # and with different numbers since you did not use
> set.seed(123)
>  4  7 11  8
>
> Please do clarify.
>
>
>
>> 2010/2/26 Henrique Dallazuanna 
>>
>>  Try this:
>>>
>>> split(data.frame(x, g), g)
>>>
>>> On Fri, Feb 26, 2010 at 3:55 PM, rusers.sh  wrote:
>>>
>>>> Hi,
>>>> I am using split function and wonder how to add the factor to the
>>>>
>>> splitted
>>>
>>>> results.
>>>> #Example
>>>> n <- 3; nn <- 10
>>>> g <- factor(round(n * stats::runif(n * nn)))   #factor
>>>> x <- rnorm(n * nn) + sqrt(as.numeric(g))#value
>>>> xg <- split(x, g)
>>>> xg
>>>> $`0`
>>>> [1]  0.82513702 -0.03911584  2.32955347  0.36745335  1.75572642
>>>>
>>> 2.65461438
>>>
>>>> 0.41675829
>>>> $`1`
>>>> [1]  0.8583493  2.4264804 -0.3622378  3.1770015  0.5162129
>>>> $`2`
>>>> [1] 1.7914651 1.1440121 0.8097543 1.2064742 1.6411988 1.3743778
>>>>
>>> 1.7094387
>>>
>>>> 2.1204501 1.9330132 2.0731997
>>>> [11] 2.8931865 2.5825309 0.6978723
>>>> $`3`
>>>> [1] 3.0246214 1.6870782 0.9685926 1.6449350 0.9378751
>>>>
>>>>> g
>>>>>
>>>> [1] 2 2 3 2 1 3 2 3 3 1 2 2 2 2 0 0 3 0 2 2 1 1 2 2 0 1 2 0 0 0
>>>> Levels: 0 1 2 3
>>>>
>>>> Anybody can tell me how to add the corresponding values of factor "g" to
>>>> the splitted results 'xg' to get a data frame?
>>>> Something like,
>>>>
>>>> Splitted/xg factor/g
>>>> 0.825137020
>>>> -0.03911584   0
>>>> 2.329553470
>>>>  ...
>>>> I know i can use "xg$'0',xg$'1',xg$'2',xg$'3'" to get the values of each
>>>> class and then add a new variable to indicate the factor.
>>>> But i hope to get a method to automatic do those things. Any ideas?
>>>> Thanks.
>>>>
>>>>
>>>> --
>>>>
>>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] split function

2010-02-26 Thread rusers.sh
Your method seems to only re-express the data "data.frame(x, g)" using
another format. The results are really from the generated data frame. Maybe
be not good.
> table(g)
g
0 1 2 3
7 9 8 6
  I hope to randomly split the value 'x' according to the different sample
sizes of different levels, displayed above. That is, 7 for level 0, 9 for
level 1, et al.
  Thanks.

2010/2/26 Henrique Dallazuanna 

> Try this:
>
> split(data.frame(x, g), g)
>
> On Fri, Feb 26, 2010 at 3:55 PM, rusers.sh  wrote:
> > Hi,
> >  I am using split function and wonder how to add the factor to the
> splitted
> > results.
> > #Example
> > n <- 3; nn <- 10
> > g <- factor(round(n * stats::runif(n * nn)))   #factor
> > x <- rnorm(n * nn) + sqrt(as.numeric(g))#value
> > xg <- split(x, g)
> > xg
> > $`0`
> > [1]  0.82513702 -0.03911584  2.32955347  0.36745335  1.75572642
>  2.65461438
> >  0.41675829
> > $`1`
> > [1]  0.8583493  2.4264804 -0.3622378  3.1770015  0.5162129
> > $`2`
> >  [1] 1.7914651 1.1440121 0.8097543 1.2064742 1.6411988 1.3743778
> 1.7094387
> > 2.1204501 1.9330132 2.0731997
> > [11] 2.8931865 2.5825309 0.6978723
> > $`3`
> > [1] 3.0246214 1.6870782 0.9685926 1.6449350 0.9378751
> >> g
> >  [1] 2 2 3 2 1 3 2 3 3 1 2 2 2 2 0 0 3 0 2 2 1 1 2 2 0 1 2 0 0 0
> > Levels: 0 1 2 3
> >
> >  Anybody can tell me how to add the corresponding values of factor "g" to
> > the splitted results 'xg' to get a data frame?
> > Something like,
> >
> > Splitted/xg factor/g
> > 0.825137020
> > -0.03911584   0
> > 2.329553470
> >...
> >  I know i can use "xg$'0',xg$'1',xg$'2',xg$'3'" to get the values of each
> > class and then add a new variable to indicate the factor.
> > But i hope to get a method to automatic do those things. Any ideas?
> >  Thanks.
> >
> >
> > --
> > -
> > Jane Chang
> > Queen's
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
> >
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] split function

2010-02-26 Thread rusers.sh
Hi,
  I am using split function and wonder how to add the factor to the splitted
results.
#Example
n <- 3; nn <- 10
g <- factor(round(n * stats::runif(n * nn)))   #factor
x <- rnorm(n * nn) + sqrt(as.numeric(g))#value
xg <- split(x, g)
xg
$`0`
[1]  0.82513702 -0.03911584  2.32955347  0.36745335  1.75572642  2.65461438
 0.41675829
$`1`
[1]  0.8583493  2.4264804 -0.3622378  3.1770015  0.5162129
$`2`
 [1] 1.7914651 1.1440121 0.8097543 1.2064742 1.6411988 1.3743778 1.7094387
2.1204501 1.9330132 2.0731997
[11] 2.8931865 2.5825309 0.6978723
$`3`
[1] 3.0246214 1.6870782 0.9685926 1.6449350 0.9378751
> g
 [1] 2 2 3 2 1 3 2 3 3 1 2 2 2 2 0 0 3 0 2 2 1 1 2 2 0 1 2 0 0 0
Levels: 0 1 2 3

  Anybody can tell me how to add the corresponding values of factor "g" to
the splitted results 'xg' to get a data frame?
Something like,

Splitted/xg factor/g
0.825137020
-0.03911584   0
2.329553470
...
  I know i can use "xg$'0',xg$'1',xg$'2',xg$'3'" to get the values of each
class and then add a new variable to indicate the factor.
But i hope to get a method to automatic do those things. Any ideas?
  Thanks.


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Change an array into a dataset of four variables, dim1, dim2, dim3 and its elements

2010-01-20 Thread rusers.sh
Hi,
  See my example below.
a<-array(1:12,c(2,3,2))
> a
, , 1

 [,1] [,2] [,3]
[1,]135
[2,]246

, , 2

 [,1] [,2] [,3]
[1,]79   11
[2,]8   10   12
  I want to get a result something like
dim1  dim2  dim3  elements
111
121
13 2
21 2
  I tried the data.frame and expand.grid functions, but the results are not
what i want.
  I  think there must be an easy method to do it. Anybody can tell me that
function or method? Thanks.

...


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] could we use ":" to represent multiple matrice in a list or sequential chracter names

2010-01-19 Thread rusers.sh
Hi,
  I know we can use 1:10 to represent the 1,2,3,...,10 numbers, but the
following conditions are except.
  Anybody knows how to represent the following two cases with similar usage
of ":"  or others? Usually, i will get several hundred names for them, such
as a1,a2,... or f[[1]],f[[2]],...
#Example data
a1<-array(1:12,c(2,3,2)); a2<-array(2,c(2,3,2)); a3<-array(0,c(2,3,2))
a1[1,2,1]:a3[1,2,1]
[1] 3 2 1 0
#the correct result should be 3,2,0
  So the method  of using "a1[i,j,k]:a3[i,j,k]" to represent
"c(a1[i,j,k],a2[i,j,k],a3[i,j,k])" is not correct?
##For lists with matrices as its elements
f<-list()
f[[1]]<-a1;f[[2]]<-a2;f[[3]]<-a3
f[[1]][1,2,1]:f[[3]][1,2,1]
[1] 3 2 1 0
#the correct result should be 3,2,0
   So the method  of using "f[[1]][i,j,k]:f[[3]][i,j,k]" to represent
"f[[1]][i,j,k],f[[2]][i,j,k],f[[3]][i,j,k])" is not correct?
  I noticed that the above two methods have got the same results, although
not correct. So i guess i have made the same errors in them. Is there some
method to represent them concisely?
  Any ideas about them?
  Thanks a lot.


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] forgot the function to divide a dataset into equal parts

2010-01-19 Thread rusers.sh
Yes. I am looking for them. Thanks.

2010/1/19 jim holtman 

> ?cut
> ?split
>
> On Tue, Jan 19, 2010 at 3:18 PM, rusers.sh  wrote:
> > Hi,
> >  I just cannot remember the R function to divide a dataset into equal
> > parts. And i searched the "divide dataset into equal parts"  in R site,
> but
> > cannot find it.
> >  Anybody can tell me that function. I am just blocked by it.
> >  Thanks a lot.
> > --
> > -
> > Jane Chang
> > Queen's
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] forgot the function to divide a dataset into equal parts

2010-01-19 Thread rusers.sh
Hi,
  I just cannot remember the R function to divide a dataset into equal
parts. And i searched the "divide dataset into equal parts"  in R site, but
cannot find it.
  Anybody can tell me that function. I am just blocked by it.
  Thanks a lot.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] change codes into loops

2010-01-18 Thread rusers.sh
If the number of datasets for a* is small (here is 3), it is ok for creating
b_ijn[i, j, nn] and make assignments to it. But it will be a little bit
impossible for a larger number of datasets for a*, say 999. We may need 999
lines to do this. Maybe there are other alternatives.

2010/1/18 David Winsemius 

>
> On Jan 18, 2010, at 7:19 PM, rusers.sh wrote:
>
>  Hi,
>>  See example.
>>  for (i in 1:2) {
>>  for (j in 1:3) {
>>b_1[i,j]<-rank(c(a1[i,j],a2[i,j],a3[i,j]))[1]
>>   b_2[i,j]<-rank(c(a1[i,j],a2[i,j],a3[i,j]))[2]
>>b_3[i,j]<-rank(c(a1[i,j],a2[i,j],a3[i,j]))[3]
>>  }
>> }
>>  The inner codes is really repeated, so i want to change the inner codes
>> into loops. Take nn is from 1 to 3,
>> something like,
>>  for (nn in 1:3) {
>> b_nn[i,j]<-rank(c(a1[i,j]:a3[i,j]))[nn]
>> }
>>  Anybody can tell me the correct method to specify the above codes?
>>
>
> There is no correct method. You cannot index on the object name b_nn that
> way. R has not been developing using a syntax with that much flexibility.
>  If you want a 3D array of values, then you could create b_ijn[i, j, nn] and
> make assignments to it. But if you tried to do this with paste and assign,
> you will spending considerably more time degbugging it than it is worth and
> it would likely be more inefficient than what you have.
>
> --
> David.
>
>  Thanks.
>>
>> --
>> -
>> Jane Chang
>> Queen's
>>
>>[[alternative HTML version deleted]]
>>
>>
>> __
>> R-help@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.
>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] change codes into loops

2010-01-18 Thread rusers.sh
Hi,
  See example.
   for (i in 1:2) {
  for (j in 1:3) {
 b_1[i,j]<-rank(c(a1[i,j],a2[i,j],a3[i,j]))[1]
b_2[i,j]<-rank(c(a1[i,j],a2[i,j],a3[i,j]))[2]
 b_3[i,j]<-rank(c(a1[i,j],a2[i,j],a3[i,j]))[3]
  }
}
  The inner codes is really repeated, so i want to change the inner codes
into loops. Take nn is from 1 to 3,
 something like,
  for (nn in 1:3) {
 b_nn[i,j]<-rank(c(a1[i,j]:a3[i,j]))[nn]
}
  Anybody can tell me the correct method to specify the above codes?
 Thanks.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] problem of data manipulation

2010-01-18 Thread rusers.sh
I just remembered that my actual dataset for var2 and var3
are numerical data,e.g. 12.34, not factors. The above example data is
misleading.
  Suppose var2 and var3 are numerical variables, not factors. How should we
do it?
  Very sorry for the misleading.

2010/1/18 William Dunlap 

> > -Original Message-
> > From: Bert Gunter [mailto:gunter.ber...@gene.com]
> > Sent: Monday, January 18, 2010 12:32 PM
> > To: William Dunlap; 'rusers.sh'; r-help@r-project.org
> > Subject: RE: [R] problem of data manipulation
> >
> > Absolutely... so long as you assume the dates are in order --
> > or at least
> > that the earliest date of a group appears first.
> >
> > -- Bert
> >
>
> Yes, I forgot to mention that requirement.  When
> there are a lot of small groups run-based methods
> (sort then deal with a run at a time) can save a
> lot of time.  They may also make the intent of
> the code more clear, but not everyone sees it that way.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> > -Original Message-
> > From: r-help-boun...@r-project.org
> > [mailto:r-help-boun...@r-project.org] On
> > Behalf Of William Dunlap
> > Sent: Monday, January 18, 2010 12:15 PM
> > To: Bert Gunter; rusers.sh; r-help@r-project.org
> > Subject: Re: [R] problem of data manipulation
> >
> > > -Original Message-
> > > From: r-help-boun...@r-project.org
> > > [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
> > > Sent: Monday, January 18, 2010 11:54 AM
> > > To: 'rusers.sh'; r-help@r-project.org
> > > Subject: Re: [R] problem of data manipulation
> > >
> > > One way to do it:
> > >
> > > 1. Convert your date column to the Date class using the
> > > as.Date() function.
> > > This allows you to do the necessary arithmetic on the dates below.
> > > dt <- as.Date(a[,4],"%d/%m/%Y")
> > >
> > > 2. Create a factor out of your first three columns whose
> > > levels are in the
> > > same order as the unique rows. Something likes the following
> > > should do it:
> > > fac <- do.call(paste,a[,-4])
> > > fac <- factor(fac, levels=unique(fac))
> > >
> > > This allows you to choose the groups of rows whose dates you
> > > wish to compare
> > > and maintain their correct order in the data frame
> > >
> > > 3. Then use tapply:
> > > a[unlist(tapply(dt,fac,function(x)x-min(x) < 7)),]
> >
> > You can do this without unpacking and repacking
> > the data.frame (with tapply) based on the following
> > sort of calculation:
> >
> >   > isFirstInRun <- function(x)c(TRUE, x[-1] != x[-length(x)])
> >   > f <- with(a, isFirstInRun(var1) | isFirstInRun(var2) |
> > isFirstInRun(var3))
> >   > firstRowInRun <- which(f)
> >   > runNumber <- cumsum(f)
> >   > dt <- as.Date(a$var4, "%d/%m/%Y")
> >   > DaysSinceStartOfRun <- dt - dt[firstRowInRun[runNumber]]
> >   > DaysSinceStartOfRun
> >   Time differences in days
> >   [1]  0  0  3  0  4 12
> >   > a[ DaysSinceStartOfRun < 7, ]
> > var1 var2 var3   var4
> >   1s12 01/01/1999
> >   2c12 10/02/2000
> >   3c12 13/02/2000
> >   4n21 11/02/2000
> >   5n21 15/02/2000
> >
> > Is that what you wanted?
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> > >
> > > (unlist is needed to remove the list structure and
> > > concatenate the logical
> > > indices to obtain the subscripting vector).
> > >
> > > Bert Gunter
> > > Genentech Nonclinical Statistics
> > >
> > > -Original Message-
> > > From: r-help-boun...@r-project.org
> > > [mailto:r-help-boun...@r-project.org] On
> > > Behalf Of rusers.sh
> > > Sent: Monday, January 18, 2010 10:40 AM
> > > To: r-help@r-project.org
> > > Subject: [R] problem of data manipulation
> > >
> > > Hello,
> > >   See my problem below.
> > > a<-data.frame(c("s","c","c","n","n","n"),c(rep(1,3),rep(2,3)),
> > > c(rep(2,3),rep
> > > (1,3)),c("01/01/1999","10/02/2000","13/02/2000","11/02/2000","
> > > 15/02/2000","2
> > > 3/02/2000"))
> > > colnames(a)<-c("var1

Re: [R] problem of data manipulation

2010-01-18 Thread rusers.sh
Thank you so much. I got it.

2010/1/18 William Dunlap 

> > -Original Message-
> > From: Bert Gunter [mailto:gunter.ber...@gene.com]
> > Sent: Monday, January 18, 2010 12:32 PM
> > To: William Dunlap; 'rusers.sh'; r-help@r-project.org
> > Subject: RE: [R] problem of data manipulation
> >
> > Absolutely... so long as you assume the dates are in order --
> > or at least
> > that the earliest date of a group appears first.
> >
> > -- Bert
> >
>
> Yes, I forgot to mention that requirement.  When
> there are a lot of small groups run-based methods
> (sort then deal with a run at a time) can save a
> lot of time.  They may also make the intent of
> the code more clear, but not everyone sees it that way.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> > -Original Message-
> > From: r-help-boun...@r-project.org
> > [mailto:r-help-boun...@r-project.org] On
> > Behalf Of William Dunlap
> > Sent: Monday, January 18, 2010 12:15 PM
> > To: Bert Gunter; rusers.sh; r-help@r-project.org
> > Subject: Re: [R] problem of data manipulation
> >
> > > -Original Message-
> > > From: r-help-boun...@r-project.org
> > > [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
> > > Sent: Monday, January 18, 2010 11:54 AM
> > > To: 'rusers.sh'; r-help@r-project.org
> > > Subject: Re: [R] problem of data manipulation
> > >
> > > One way to do it:
> > >
> > > 1. Convert your date column to the Date class using the
> > > as.Date() function.
> > > This allows you to do the necessary arithmetic on the dates below.
> > > dt <- as.Date(a[,4],"%d/%m/%Y")
> > >
> > > 2. Create a factor out of your first three columns whose
> > > levels are in the
> > > same order as the unique rows. Something likes the following
> > > should do it:
> > > fac <- do.call(paste,a[,-4])
> > > fac <- factor(fac, levels=unique(fac))
> > >
> > > This allows you to choose the groups of rows whose dates you
> > > wish to compare
> > > and maintain their correct order in the data frame
> > >
> > > 3. Then use tapply:
> > > a[unlist(tapply(dt,fac,function(x)x-min(x) < 7)),]
> >
> > You can do this without unpacking and repacking
> > the data.frame (with tapply) based on the following
> > sort of calculation:
> >
> >   > isFirstInRun <- function(x)c(TRUE, x[-1] != x[-length(x)])
> >   > f <- with(a, isFirstInRun(var1) | isFirstInRun(var2) |
> > isFirstInRun(var3))
> >   > firstRowInRun <- which(f)
> >   > runNumber <- cumsum(f)
> >   > dt <- as.Date(a$var4, "%d/%m/%Y")
> >   > DaysSinceStartOfRun <- dt - dt[firstRowInRun[runNumber]]
> >   > DaysSinceStartOfRun
> >   Time differences in days
> >   [1]  0  0  3  0  4 12
> >   > a[ DaysSinceStartOfRun < 7, ]
> > var1 var2 var3   var4
> >   1s12 01/01/1999
> >   2c12 10/02/2000
> >   3c12 13/02/2000
> >   4n21 11/02/2000
> >   5n21 15/02/2000
> >
> > Is that what you wanted?
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> > >
> > > (unlist is needed to remove the list structure and
> > > concatenate the logical
> > > indices to obtain the subscripting vector).
> > >
> > > Bert Gunter
> > > Genentech Nonclinical Statistics
> > >
> > > -Original Message-
> > > From: r-help-boun...@r-project.org
> > > [mailto:r-help-boun...@r-project.org] On
> > > Behalf Of rusers.sh
> > > Sent: Monday, January 18, 2010 10:40 AM
> > > To: r-help@r-project.org
> > > Subject: [R] problem of data manipulation
> > >
> > > Hello,
> > >   See my problem below.
> > > a<-data.frame(c("s","c","c","n","n","n"),c(rep(1,3),rep(2,3)),
> > > c(rep(2,3),rep
> > > (1,3)),c("01/01/1999","10/02/2000","13/02/2000","11/02/2000","
> > > 15/02/2000","2
> > > 3/02/2000"))
> > > colnames(a)<-c("var1","var2","var3","var4")
> > > > a
> > >   var1 var2 var3   var4
> > > 1s1201/01/1999
> > > 2c1210/02/2000
> > > 3 

[R] problem of data manipulation

2010-01-18 Thread rusers.sh
Hello,
  See my problem below.
a<-data.frame(c("s","c","c","n","n","n"),c(rep(1,3),rep(2,3)),c(rep(2,3),rep(1,3)),c("01/01/1999","10/02/2000","13/02/2000","11/02/2000","15/02/2000","23/02/2000"))
colnames(a)<-c("var1","var2","var3","var4")
> a
  var1 var2 var3   var4
1s1201/01/1999
2c1210/02/2000
3c1213/02/2000
4n2111/02/2000
5n2115/02/2000
6n2123/02/2000

  I want to select the observations whose difference of "var4" is less than
7 for the cases with the same values of var1,var2 andvar3.
  The obervations have the same var1, var2 and var3 are, part1 (obs2 and
obs3) and part2 (obs4,obs5, and obs6).
  For obs2 and obs3, their date difference is less than 7, so we donot need
to delete any of them.
  For obs4,obs5, and obs6,we can see that obs6 should be deleted becuase its
date is over 7 dyas longer than obs4.
  So the final dataset should obs1,obs2,obs3,obs4, and obs5.
  I have a lot of observations in my dataset, so i hope to do this
automatically.  Any ideas on this?
  Thanks.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] get the ranks for arrays

2010-01-18 Thread rusers.sh
Hello,
  'rank' function seems to be only for vectors, but i need to get the ranks
for 3-dimensional arrays. See problems below.
#Example Data

a1<-array(1:12,c(2,3,2)); a2<-array(2,c(2,3,2)); a3<-array(0,c(2,3,2))

 > a1

, , 1

   [,1] [,2] [,3]

[1,]135

[2,]246

, , 2

  [,1] [,2] [,3]

[1,]79   11

[2,]8   10   12

 > a2

, , 1

  [,1] [,2] [,3]

[1,]222

[2,]222

, , 2

  [,1] [,2] [,3]

[1,]222

[2,]222

 > a3

, , 1

  [,1] [,2] [,3]

[1,]000

[2,]000

 , , 2

  [,1] [,2] [,3]

[1,]000

[2,]000

rank(a1,a2,a3)  #rank seems to be only for vectors

 Anybody knows how to rank these arrays and get the new arrays with ranks as
their elements instead of original values?

  The results are like,

 > a1_rank

, , 1

  [,1] [,2] [,3]

[1,]233

[2,]2.533

 , , 2

  [,1] [,2] [,3]

[1,]33   3

[2,]3   33

 > a2_rank

, , 1

  [,1] [,2] [,3]

[1,]222

[2,]2.522

 , , 2

  [,1] [,2] [,3]

[1,]222

[2,]222

 > a3_rank

, , 1

  [,1] [,2] [,3]

[1,]111

[2,]111

 , , 2

  [,1] [,2] [,3]

[1,]111

[2,]111

  Thanks a lot.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] "%d/%m/%Y" can not be displayed in a .rd file

2010-01-07 Thread rusers.sh
Solved. Thanks a lot.

2010/1/7 Duncan Murdoch 

> On 07/01/2010 2:09 PM, rusers.sh wrote:
>
>> Hi all,
>>  I found the date format (e.g."%d/%m/%Y") in the .rd file cannot be
>> displayed after building the package. See below,
>> ###.rd file
>> \examples{
>> a<-"10/20/1999"
>> DateConversion(a,DateIn="%m/%d/%Y",DateOut="%d/%m/%Y")
>> }
>> The result is 
>> Examples:
>> a<-"10-20-1999"
>> DateConversion(a,DateIn="
>>
>>  ??"%m/%d/%Y" seems cannot be recognized.
>>Is there some method to solve this and make it visible?
>>  Thanks a lot.
>>
>
>
> The % character is a comment character in Rd files.  You need to escape it:
>
>
> DateConversion(a,DateIn="\%m/\%d/\%Y",DateOut="\%d/\%m/\%Y")
>
>
>
> Duncan Murdoch
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] "%d/%m/%Y" can not be displayed in a .rd file

2010-01-07 Thread rusers.sh
Hi all,
  I found the date format (e.g."%d/%m/%Y") in the .rd file cannot be
displayed after building the package. See below,
###.rd file
\examples{
a<-"10/20/1999"
DateConversion(a,DateIn="%m/%d/%Y",DateOut="%d/%m/%Y")
}
The result is 
Examples:
 a<-"10-20-1999"
 DateConversion(a,DateIn="

  ??"%m/%d/%Y" seems cannot be recognized.
Is there some method to solve this and make it visible?
  Thanks a lot.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Anybody can suggest a better method to build a package while ignoring some functions

2010-01-05 Thread rusers.sh
Hi,
 Say i have three functions in a new package, a,b and c. I only want the one
function "a" to be exported for use. "b" and  "c" are not very stable.
  If i specify to export all the three functions in the NAMESPACE file
(export(a,b,c)), no errors appeared after checking the package. And i am
sure there should be no errors.
  But if i only export the one function "a" by specifying it in the
NAMESPACE file(export(a)), one error appeared.
  See below.
 Error ###
* checking examples ... ERROR
Running examples in 's-Ex.R' failed.
The error most likely occurred in:
> ### * b
>
> flush(stderr()); flush(stdout())
>
> ### Name: b
> ### Title: Compute inverse cosine with angle given in degrees
> ### Aliases: ab
> ### Keywords: array
>
> ### ** Examples
> b(theta=30)
Error: could not find function "acos_d"
Execution halted
  Anybody knows where the problem is and how to solve this? Is there better
method to obtain what i want?
  Thanks

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Error on checking a package with some functions ignored

2010-01-04 Thread rusers.sh
Hi,
 Say i have three functions in a new package, a,b and c. I only want the one
function "a" to be exported for use. "b" and  "c" are not very stable.
  If i specify to export all the three functions in the NAMESPACE file
(export(a,b,c)), no errors appeared after checking the package. But if i
only export the only one function "a" in the NAMESPACE file(export(a)), one
error appeared.
  See below.
 Error ###
* checking examples ... ERROR
Running examples in 's-Ex.R' failed.
The error most likely occurred in:
> ### * b
>
> flush(stderr()); flush(stdout())
>
> ### Name: b
> ### Title: Compute inverse cosine with angle given in degrees
> ### Aliases: ab
> ### Keywords: array
>
> ### ** Examples
> b(theta=30)
Error: could not find function "acos_d"
Execution halted
  Anybody knows where the problem is and how to solve this? Is there better
method to obtain what i want?
  Thanks.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] checking package errors-'require' calls not declared and no visible global function definition

2009-12-24 Thread rusers.sh
 Thanks.
 BTW, if i have three functions, a,b and c. I only want the two functions
"a" and "b" to be exported for use and "c" is  only used by myself because
it is not very stable.
  How to set this?
 Thanks a lot.

2009/12/24 Gabor Grothendieck 

> The first one is a warning and the second is a note.  You did not get
> any errors.
>
> On Thu, Dec 24, 2009 at 9:40 PM, rusers.sh  wrote:
> > Hi,
> >  I got two errors after i checking my package. The errors are as follows,
> > Error1:
> > * checking for unstated dependencies in R code ... WARNING
> > 'library' or 'require' calls not declared from:
> >  boot np
> >
> > Error2:
> > * checking R code for possible problems ... NOTE
> > myfunction: no visible global function definition for 'npudensbw'in the
> np
> > package
> >
> >  In "myfunction", i have two requires "require(boot)" and "require(np)",
> > but i have stated them in the DESCRIPTION file using "Depends:boot,np".
> >  Anybody can give me some ideas to clear these two errors,'require' calls
> > not declared and no visible global function definition?
> >  Thanks a lot.
> >
> > --
> > -
> > Jane Chang
> > Queen's
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
> >
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] checking package errors-'require' calls not declared and no visible global function definition

2009-12-24 Thread rusers.sh
Hi,
  I got two errors after i checking my package. The errors are as follows,
Error1:
* checking for unstated dependencies in R code ... WARNING
'library' or 'require' calls not declared from:
  boot np

Error2:
* checking R code for possible problems ... NOTE
myfunction: no visible global function definition for 'npudensbw'in the np
package

  In "myfunction", i have two requires "require(boot)" and "require(np)",
but i have stated them in the DESCRIPTION file using "Depends:boot,np".
  Anybody can give me some ideas to clear these two errors,'require' calls
not declared and no visible global function definition?
  Thanks a lot.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] insert a dot to the numbers

2009-12-21 Thread rusers.sh
Thanks a lot.

2009/12/20 Henrique Dallazuanna 

> Try this also:
>
> sapply(s, function(x)format(x, big.interval = nchar(x) - 3, big.mark =
> "."))
>
> On Sun, Dec 20, 2009 at 7:50 PM, rusers.sh  wrote:
> > Hi,
> >  Anybody can give me some hints on the following problem?
> > s<-c(110,112321)
> >  I want to insert a dot "." after the third number and get the following
> > results.
> > 110.
> > 112.321
> >
> >  Thanks a lot.
> >
> > --
> > -
> > Jane Chang
> > Queen's
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
> >
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] insert a dot to the numbers

2009-12-20 Thread rusers.sh
Hi,
  Anybody can give me some hints on the following problem?
s<-c(110,112321)
  I want to insert a dot "." after the third number and get the following
results.
110.
112.321

  Thanks a lot.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Error for making packages under windows XP-Error in library.dynam(lib, package, package.lib)

2009-12-17 Thread rusers.sh
Dear Duncan,
  I just followed an example to try making a package. The problem is really
on the useDynLib. It works after i delete it.
 Thanks a lot.

2009/12/17 Duncan Murdoch 

> rusers.sh wrote:
>
>> Hi,
>>  I have installed the necessary tools for making a R package under windows
>> and am sure these tool have been correctly configured. I am very new to
>> try
>> writing a package, so the error may be very obvious for you. Forgive me if
>> it is too easy.
>>  My package name is *stam*, and i put it under the folder
>> "D:/StatSoft/R/MyPackage/". I have two folders,*R* and *man*. Besides, i
>> also have *description* and *namespace** *files. It is a very simple beta
>> package.
>>
>>
>
> The DESCRIPTION and NAMESPACE files should be specified in upper case, but
> that's probably not your problem.  I would guess you have a command that
> says to load a shared library, e.g. a useDynLib statement in your NAMESPACE,
> or a library.dynam in a .First() function.  Just delete it, without compiled
> code (which would be kept in the src directory) you don't need it.
>
> Duncan Murdoch
>
>   Following is the error after using "R CMD check mypackage". Thanks very
>> much.
>> #
>> * using log directory 'D:/StatSoft/R/MyPackage/stam.Rcheck'
>> * using R version 2.10.0 (2009-10-26)
>> * using session charset: ISO8859-1
>> * checking for file 'stam/DESCRIPTION' ... OK
>> * this is package 'stam' version '1.0-0'
>> * checking package name space information ... OK
>> * checking package dependencies ... OK
>> * checking if this is a source package ... OK
>> * checking for executable files ... OK
>> * checking whether package 'stam' can be installed ... OK
>> * checking package directory ... OK
>> * checking for portable file names ... OK
>> * checking DESCRIPTION meta-information ... OK
>> * checking top-level files ... OK
>> * checking index information ... OK
>> * checking package subdirectories ... OK
>> * checking R files for non-ASCII characters ... OK
>> * checking R files for syntax errors ... OK
>> * checking whether the package can be loaded ... ERROR
>> Error in library.dynam(lib, package, package.lib) :
>>  shared library 'stam' not found
>> Error: package/namespace load failed for 'stam'
>> Execution halted
>>
>> It looks like this package has a loading problem: see the messages for
>> details.
>>
>> #
>>
>>
>>
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Error for making packages under windows XP-Error in library.dynam(lib, package, package.lib)

2009-12-16 Thread rusers.sh
Hi,
  I have installed the necessary tools for making a R package under windows
and am sure these tool have been correctly configured. I am very new to try
writing a package, so the error may be very obvious for you. Forgive me if
it is too easy.
  My package name is *stam*, and i put it under the folder
"D:/StatSoft/R/MyPackage/". I have two folders,*R* and *man*. Besides, i
also have *description* and *namespace** *files. It is a very simple beta
package.
  Following is the error after using "R CMD check mypackage". Thanks very
much.
#
* using log directory 'D:/StatSoft/R/MyPackage/stam.Rcheck'
* using R version 2.10.0 (2009-10-26)
* using session charset: ISO8859-1
* checking for file 'stam/DESCRIPTION' ... OK
* this is package 'stam' version '1.0-0'
* checking package name space information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for executable files ... OK
* checking whether package 'stam' can be installed ... OK
* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... ERROR
Error in library.dynam(lib, package, package.lib) :
  shared library 'stam' not found
Error: package/namespace load failed for 'stam'
Execution halted

It looks like this package has a loading problem: see the messages for
details.

#

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Confused on using expand.grid(), array(), image() and npudens(np) in my case

2009-12-13 Thread rusers.sh
Hi all,
  I want to use the npudens() function in the np package (multivariate
kernel density estimation), but was confused by the several functions in the
following codes,expand.grid(),array(),image() and npudensbw().
  This confusion will only be generated in >=3 dimensions. I marked the four
places with confusion1-4. I think there should be some kind
of correspondence in those four places,but cannot figure them out.Thanks
very much for chewing on this.
#simulated dataset: d
x1<-c(runif(100,0,1),runif(50,0.67,1));y1<-c(runif(100,0,1),runif(50,0.67,1));d1<-data.frame(x1,y1);colnames(d1)<-c("x","y")
x2<-c(runif(100,0,1),runif(50,0.33,0.67));y2<-c(runif(100,0,1),runif(50,0.33,0.67));d2<-data.frame(x2,y2);colnames(d2)<-c("x","y")
x3<-c(runif(100,0,1),runif(50,0,0.33));y3<-c(runif(100,0,1),runif(50,0,0.33));d3<-data.frame(x3,y3);colnames(d3)<-c("x","y")
d<-rbind(d1,d2,d3)
d$tf<-c(rep(1,150),rep(2,150),rep(3,150))
plot(d1);points(d2,col="red");points(d3,col="green")
attach(d)

#Confusion1:how to specify the formula in the npudensbw() correctly? I find
the sequence of ordered(tf)+x+y is important and here i may have a wrong
specification

bw <- npudensbw(formula=~ordered(tf)+x+y, bwmethod="cv.ml")  #confusion1

year.seq <- sort(unique(d$tf))  #length is 3
x.seq <- seq(0,1,0.02)  #length is 51
y.seq <- seq(0,1,0.02)  #length is 51

#Confusion2:what is the correct sequence for the three variables
(year.seq,x.seq and y.seq) in expand.grid()

data.eval <- expand.grid(tf=year.seq,x=x.seq,y=y.seq)  #confusion2

fhat <- fitted(npudens(bws=bw, newdata=data.eval))

#Confusion3:what is the correct sequence for the three variables in the c()
options of array()

f <- array(fhat, c(51,51,3))  #number of year.seq is 3, and number of x.seq
and y.seq are 51,confusion3

brks <- quantile(f, seq(0,1,0.05));cols <-
heat.colors(length(brks)-1);oldpar <- par(mfrow=c(1,3))

#Confusion4:what is the correct sequence for the three variables(tf,x and y)
in the image()

for (i in 1:3) image(x.seq, y.seq, f[,,i],asp=1, xlab="", ylab="", main=i,
breaks=brks, col=cols)  #confusion4

par(oldpar)

#This was also confused in 4 ,5 and more dimensions.
  Any help or suggestions are greatly appreciated.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Why cannot get the expected values in my function

2009-12-09 Thread rusers.sh
Thanks very very much. It is really not easy to change from one language to
another. :)

2009/12/9 Gavin Simpson 

> On Tue, 2009-12-08 at 23:22 -0500, David Winsemius wrote:
> > On Dec 8, 2009, at 11:07 PM, rusers.sh wrote:
> >
> > > Hi,
> > >  In the following function, i hope to save my simulated data into the
> > > "result" dataset, but why the final "result" dataset seems not to be
> > > generated.
> >
> >
> > > #Function
> > > simdata<-function (nsim) {
> >
> > # Instead why not:
> > cbind(x=runif(nsim), y=runif(nsim) )
>
> or:
>
> m <- matrix(runif(nsim*2), ncol = 2)
> ## if names on m needed
> colnames(m) <- c("x","y")
>
> G
>
> > >  }
> > >
> > > #simulation
> > >> simdata(10)  #correct result
> > >  x   y
> > > [1,] 0.2655087 0.372123900
> > > [2,] 0.1848823 0.702374036
> > > [3,] 0.1680415 0.807516399
> > > [4,] 0.5858003 0.008945796
> > > [5,] 0.2002145 0.685218596
> > > [6,] 0.6062683 0.937641973
> > > [7,] 0.9889093 0.397745453
> > > [8,] 0.4662952 0.207823317
> > > [9,] 0.2216014 0.024233910
> > > [10,] 0.5074782 0.306768506
> > >  But, the dataset "result" wasnot assigned the above values. What is
> > > the
> > > problem?
> > >> result  #wrong result??
> > >   x  y
> > > [1,] NA NA
> > > [2,] NA NA
> > > [3,] NA NA
> > > [4,] NA NA
> > > [5,] NA NA
> > > [6,] NA NA
> > > [7,] NA NA
> > > [8,] NA NA
> > > [9,] NA NA
> > > [10,] NA NA
> > >>
> > > Thanks a lot.
> > > --
> > > -
> > > Jane Chang
> > > Queen's
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@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.
> >
> > David Winsemius, MD
> > Heritage Laboratories
> > West Hartford, CT
> >
> > __
> > R-help@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.
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  Dr. Gavin Simpson [t] +44 (0)20 7679 0522
>  ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
>  Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
>  Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
>  UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] Why cannot get the expected values in my function

2009-12-08 Thread rusers.sh
Hi,
  In the following function, i hope to save my simulated data into the
"result" dataset, but why the final "result" dataset seems not to be
generated.
#Function
simdata<-function (nsim) {
 result<-matrix(NA,nrow=nsim,ncol=2)
 colnames(result)<-c("x","y")
 for (i in 1:nsim) {
 set.seed(i)
 result[i,]<- cbind(runif(1),runif(1))
 }
  return(result)
 }

#simulation
> simdata(10)  #correct result
  x   y
 [1,] 0.2655087 0.372123900
 [2,] 0.1848823 0.702374036
 [3,] 0.1680415 0.807516399
 [4,] 0.5858003 0.008945796
 [5,] 0.2002145 0.685218596
 [6,] 0.6062683 0.937641973
 [7,] 0.9889093 0.397745453
 [8,] 0.4662952 0.207823317
 [9,] 0.2216014 0.024233910
[10,] 0.5074782 0.306768506
  But, the dataset "result" wasnot assigned the above values. What is the
problem?
> result  #wrong result??
   x  y
 [1,] NA NA
 [2,] NA NA
 [3,] NA NA
 [4,] NA NA
 [5,] NA NA
 [6,] NA NA
 [7,] NA NA
 [8,] NA NA
 [9,] NA NA
[10,] NA NA
>
 Thanks a lot.
-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] why the same values cannot be judged to be the same in R

2009-11-13 Thread rusers.sh
Thanks all.
 "%in%" is what i need.

2009/11/13 jim holtman 

> I think you want to use '%in%' instead of '=='.  Try debugging (or
> understanding) what is happening by evaluating the subexpressions of
> the compares you have in your original posting.  Also take a look at
> the 'recycling' of arguments and then you may understand what is
> happening:
>
> > data2[(data2$x1 %in% data_1$x1) & (data2$y1 %in% data_1$y1) & (data2$tag
> == 0),]
>   areaid   x1   y1 tag
> 2  1 1.53 2.34   0
> 4  1 1.52 2.35   0
> >
>
>
> On Thu, Nov 12, 2009 at 10:04 PM, rusers.sh  wrote:
> > Hi Rusers,
> >  I found sometimes that the same values cannot be judged to be the same
> in
> > R. Anybody knows the probelm? I think i ignored some minor detail.
> Thanks.
> > Here is the example.
> > 
> >
> data1<-matrix(data=c(1,1.2,1.3,"3/23/2004",1,1.5,2.3,"3/22/2004",2,0.2,3.3,"4/23/2004",3,1.5,1.3,"5/22/2004"),nrow=4,ncol=4,byrow=TRUE)
> > data1<-data.frame(data1);names(data1)<-c("areaid","x","y","date")
> > data2<-matrix(data=c(1,1.22,1.32,1,  1.53,  2.34,1,  1.21,  1.37,1,
>  1.52,
> > 2.35,2,  0.21,  3.33,2,  0.23,  3.35,3,  1.57, 1.31,3,  1.59,
> > 1.33),nrow=8,ncol=3,byrow=TRUE)
> > data2<-data.frame(data2);names(data2)<-c("areaid","x1","y1")
> > data2$tag<-0
> > data1_1<-data1[1,]
> > data2_1<-data2[data2$areaid==data1_1$areaid & data2$tag==0,]
> > ran_1<-sample(c(1:length(data2_1)),2, replace = FALSE)
> > data2_1<-data2_1[ran_1,]
> > data_1<-merge(data1_1,data2_1)
> > #data_1
> > #   areaid  x   y  date   x1   y1  tag
> > #1  1 1.2 1.3 3/23/2004 1.52 2.35   0
> > #2  1 1.2 1.3 3/23/2004 1.53 2.34   0
> > data2[data_1$x1==data2$x1 & data_1$y1==data2$y1 & data2$tag==0,]
> >  #data2[c(data_1$x1==data2$x1 & data_1$y1==data2$y1 & data2$tag==0),]
> > #areaid   x1y1   tag
> > #2  11.53  2.34   0
> >  There should be two same observations between data_1 and data2, but here
> > only one was identified.
> >  Thanks a lot.
> >
> > --
> > -
> > Jane Chang
> > Queen's
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>



-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] why the same values cannot be judged to be the same in R

2009-11-12 Thread rusers.sh
Hi Rusers,
  I found sometimes that the same values cannot be judged to be the same in
R. Anybody knows the probelm? I think i ignored some minor detail. Thanks.
Here is the example.

data1<-matrix(data=c(1,1.2,1.3,"3/23/2004",1,1.5,2.3,"3/22/2004",2,0.2,3.3,"4/23/2004",3,1.5,1.3,"5/22/2004"),nrow=4,ncol=4,byrow=TRUE)
data1<-data.frame(data1);names(data1)<-c("areaid","x","y","date")
data2<-matrix(data=c(1,1.22,1.32,1,  1.53,  2.34,1,  1.21,  1.37,1,  1.52,
2.35,2,  0.21,  3.33,2,  0.23,  3.35,3,  1.57, 1.31,3,  1.59,
1.33),nrow=8,ncol=3,byrow=TRUE)
data2<-data.frame(data2);names(data2)<-c("areaid","x1","y1")
data2$tag<-0
data1_1<-data1[1,]
data2_1<-data2[data2$areaid==data1_1$areaid & data2$tag==0,]
ran_1<-sample(c(1:length(data2_1)),2, replace = FALSE)
data2_1<-data2_1[ran_1,]
data_1<-merge(data1_1,data2_1)
#data_1
#   areaid  x   y  date   x1   y1  tag
#1  1 1.2 1.3 3/23/2004 1.52 2.35   0
#2  1 1.2 1.3 3/23/2004 1.53 2.34   0
data2[data_1$x1==data2$x1 & data_1$y1==data2$y1 & data2$tag==0,]
 #data2[c(data_1$x1==data2$x1 & data_1$y1==data2$y1 & data2$tag==0),]
#areaid   x1y1   tag
#2  11.53  2.34   0
  There should be two same observations between data_1 and data2, but here
only one was identified.
  Thanks a lot.

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] how to stop a loop in a sampling

2009-11-09 Thread rusers.sh
Hi,
  When i tried to merge two datasets (multiple to multiple merge), i met a
problem on how to stop a possible loop in the sampling arguments.
###My codes are as follows.###
data1<-matrix(data=c(1,1.2,1.3,"3/23/2004",1,1.5,2.3,"3/22/2004",2,0.2,3.3,"4/23/2004",3,1.5,1.3,"5/22/2004"),nrow=4,ncol=4,byrow=TRUE)
data1<-data.frame(data1);names(data1)<-c("areaid","x","y","date")
data2<-matrix(data=c(1,1.22,1.32,1,  1.53,  2.34,1,  1.21,  1.37,1,  1.52,
2.35,2,  0.21,  3.33,2,  0.23,  3.35,3,  1.57, 1.31,3,  1.59,
1.33),nrow=8,ncol=3,byrow=TRUE)
data2<-data.frame(data2);names(data2)<-c("areaid","x1","y1")
id<-unique(data1$areaid)
for (n in id) {
 data1_n<-data1[data1$areaid==n,]
 data2_n<-data2[data2$areaid==n,]
 leg1_n<-length(data1_n$areaid)
 leg2_n<-length(data2_n$areaid)
 if (leg1_n=1) merge(data1_n,data2_n,by.x="areaid",by.y="areaid") else
   {
#leg1_n=1>=2
   #leg1_1=2 and leg2_1=4 for areaid=1
  set.seed(1000)
  samp1_n<-sample(c(1:leg1_n),1, replace = FALSE)
  data1_n_samp1<-data1_n[samp1_n,]
  samp2_n<-sample(c(1:leg2_n),2, replace = FALSE)
  data2_n_samp2<-data2_n[samp2_n,]
  merge(data1_n_samp1,data2_n_samp2,by.x="areaid",by.y="areaid")
  #need to continue to sample from the remained records in data1_n and
data2_n??
  #some criteria to stop the sampling maybe needed?
  }
 }
#merge all the above dataset to get the final results.

  Any ideas or suggestions on the problem? Thanks a lot.

###My question is explained in detail###

 two datasets, data1 and data2.

##

data1<-matrix(data=c(1,1.2,1.3,"3/23/2004",1,1.5,2.3,"3/22/2004",2,0.2,3.3,"4/23/2004",3,1.5,1.3,"5/22/2004"),nrow=4,ncol=4,byrow=TRUE)

data1<-data.frame(data1)

names(data1)<-c("areaid","x","y","date")

data1

   areaid   x   y  date

1  1 1.2 1.3 3/23/2004

2  1 1.5 2.3 3/22/2004

3  2 0.2 3.3 4/23/2004

4  3 1.5 1.3 5/22/2004

##

data2<-matrix(data=c(1,1.22,1.32,1,  1.53,  2.34,1,  1.21,  1.37,1,  1.52,
2.35,2,  0.21,  3.33,2,  0.23,  3.35,3,  1.57, 1.31,3,  1.59,
1.33),nrow=8,ncol=3,byrow=TRUE)

data2<-data.frame(data2)

names(data2)<-c("areaid","x1","y1")

data2

   areaid x1   y1

1  1 1.22 1.32

2  1 1.53 2.34

3  1 1.21 1.37

4  1 1.52 2.35

5  2 0.21 3.33

6  2 0.23 3.35

7  3 1.57 1.31

8  3 1.59 1.33

  Explains the two data. You can treat data1 as case dataset and data2 as
control dataset,respectively.Note th number of recodes for data2 are 2 times
as that of data1 for each records,something like 1:2 matched case-control
study design. I hope to merge data1 and data2. Take areaid=1 as an example.
>From the two dataset, we can see that data1 has two points(x,y) in areaid=1,
and data2 has four points (x1,y1) in areaid=1. Each record in data1 will
have two matched records in data2. I want to randomly select 1/2 points of
areaid=1 in data2 to link the one record of areaid=1 in the data1, and the
other 1/2 points of areaid=1 in data2 to link the other one record of
areaid=1 in the data1.Actually, the number of records in the same areaid
will be over 2 in the actual dataset1. This is only an example to explain
the problem.  For the cases of areaid=2 or 3,they are a little easier than
areaid=1 because there are only one value in data1.

  The key or match variable is just areaid.

  The final results are something like the following dataset.

areaid x1 y1date x  y

1  1.22  1.32  3/23/2004   1.2  1.3

1  1.53  2.34  3/22/2004   1.2  1.3

1  1.21  1.37  3/23/2004   1.5  2.3

1  1.52  2.35  3/22/2004   1.5  2.3

2  0.21  3.33  4/23/2004   0.2  3.3

2  0.23  3.35  4/23/2004   0.2  3.3

3  1.57  1.31  5/22/2004   1.5  1.3

3  1.59  1.33  5/22/2004   1.5  1.3

-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Outputing multilple subsets

2009-11-09 Thread rusers.sh
Thanks for your ideas. They are really helpful for me to think about my
question.
Cheers,
2009/11/9 David Winsemius 

>
> On Nov 9, 2009, at 8:45 AM, rusers.sh wrote:
>
> Hi Johann,
>> Excellent. That is what i really want. A little problem is why the "c.n"
>> does not exist. Should the "c.n" in the memory? Sometimes, i also hope to
>> see "c.n" directly in R besides exporting. Could i see the  "c.n" with
>> some
>> function in the loops?
>>
>
>  a<-c(1:10)
>>> b<-c(rep(1,3),rep(2,3),rep(3,4))
>>> c<-data.frame(a,b)  #c is the example data
>>>
>>
> And not a particularly good choice for a variable name by virtue of
> potential "wetware confusion" with the concatenate function, c(.)
>
>
>
>  num<-c(unique(b))
>>> for (n in num) {
>>>
>> +  c.n <- c[c$b==n,]
>> +  write.csv(c.n, file=paste("c:/c_", n, ".csv", sep=""))}
>>
>
>  num
>>>
>> [1] 1 2 3
>>
>>> c.1
>>>
>> Error: object 'c.1' not found
>>
>
> And you were apparently expecting variables "c.1", "c.2", and "c.3" to be
> constructed in that loop? That is way beyond the R-interpreter's currently
> level of integration with the device drivers reading input from the
> electroencephalograph that must be sitting on your machine.
>
> Perhaps you could have succeeded with:
>
> dftemp <- list() # outside the loop, need a list because results of the
> extract operation will be a df.
> ..
> dftemp[[n]] <- c[c$b == n, ]  # inside the loop
>  write.csv(dftemp[[n]], file=paste("c:/c_", n, ".csv", sep=""))}
>
> The fact that you immediately wrote it to a file that did not store its
> name would make creation of a list unnecessary inside the loop, but it would
> store the results in a form that could be examined later from the command
> line.
>
>
>
>  c.2
>>>
>> Error: object 'c.2' not found
>>
>>> c.3
>>>
>> Error: object 'c.3' not found
>>
>> Thanks a lot.
>> -
>> Jane Chang
>> Queen's
>>
>>
>>
>> 2009/11/9 Johann Hibschman 
>>
>> On Nov 8, 2009, at 7:23 PM, rusers.sh wrote:
>>>
>>> for (i in num)  {
>>>
>>>> c_num<-c[c$b==num,]
>>>> write.csv(c_num,file="c:/c_num.csv")
>>>> }
>>>>
>>>> Warning messages:
>>>> 1: In c$b == num :
>>>> longer object length is not a multiple of shorter object length
>>>>
>>>>
>>> This is because you're comparing column b to the entire vector of numbers
>>> (num), not the current number in the iteration (i).  The first line of
>>> the
>>> loop should be "c_num<-c[c$b==i,]".
>>>
>>> From a style point of view, I'd use "n" as my variable, since "i" is too
>>> commonly used as an integer index.
>>>
>>> Also, you will be overwriting the same file, called "c_num.csv", on each
>>> iteration.
>>>
>>> You should try something more like:
>>>
>>> for (n in num) {
>>> c.n <- c[c$b==n,]
>>> write.csv(c.n, file=paste("c:/c_", n, ".csv", sep="")
>>> }
>>>
>>> I hope that helps.
>>>
>>> Cheers,
>>> Johann Hibschman
>>>
>>>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Outputing multilple subsets

2009-11-09 Thread rusers.sh
Hi Johann,
 Excellent. That is what i really want. A little problem is why the "c.n"
does not exist. Should the "c.n" in the memory? Sometimes, i also hope to
see "c.n" directly in R besides exporting. Could i see the  "c.n" with some
function in the loops?
> a<-c(1:10)
> b<-c(rep(1,3),rep(2,3),rep(3,4))
> c<-data.frame(a,b)  #c is the example data
> num<-c(unique(b))
> for (n in num) {
+  c.n <- c[c$b==n,]
+  write.csv(c.n, file=paste("c:/c_", n, ".csv", sep=""))}
> num
[1] 1 2 3
> c.1
Error: object 'c.1' not found
> c.2
Error: object 'c.2' not found
> c.3
Error: object 'c.3' not found

 Thanks a lot.
-
Jane Chang
Queen's



2009/11/9 Johann Hibschman 

> On Nov 8, 2009, at 7:23 PM, rusers.sh wrote:
>
> for (i in num)  {
>>  c_num<-c[c$b==num,]
>>  write.csv(c_num,file="c:/c_num.csv")
>> }
>>
>> Warning messages:
>> 1: In c$b == num :
>>  longer object length is not a multiple of shorter object length
>>
>
> This is because you're comparing column b to the entire vector of numbers
> (num), not the current number in the iteration (i).  The first line of the
> loop should be "c_num<-c[c$b==i,]".
>
> From a style point of view, I'd use "n" as my variable, since "i" is too
> commonly used as an integer index.
>
> Also, you will be overwriting the same file, called "c_num.csv", on each
> iteration.
>
> You should try something more like:
>
> for (n in num) {
>  c.n <- c[c$b==n,]
>  write.csv(c.n, file=paste("c:/c_", n, ".csv", sep="")
> }
>
> I hope that helps.
>
> Cheers,
> Johann Hibschman
>
>
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] Outputing multilple subsets

2009-11-08 Thread rusers.sh
Hi Rusers,
  I hope to divide the original dataset into several subsets and output
these multilple datasets. But errors appeared in my loops. See example.
##
a<-c(1:10)
b<-c(rep(1,3),rep(2,3),rep(3,4))
c<-data.frame(a,b)  #c is the example data
num<-c(unique(b))
# I hope to get the subsets c_1.csv,c_2.csv and c_3.csv
#Errors
for (i in num)  {
   c_num<-c[c$b==num,]
   write.csv(c_num,file="c:/c_num.csv")
}

Warning messages:
1: In c$b == num :
  longer object length is not a multiple of shorter object length
2: In c$b == num :
  longer object length is not a multiple of shorter object length
3: In c$b == num :
  longer object length is not a multiple of shorter object length
  I think the problem should be file="c:/c_num.csv", anybody has ever met
this problem?
  Thanks very much.
-
Jane Chang
Queen's

[[alternative HTML version deleted]]

__
R-help@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.


[R] probem on merge data

2009-11-05 Thread rusers.sh
Hi there,
data1<-matrix(data=c(1,1.2,1.3,"3/23/2004",1,1.5,2.3,"3/22/2004",2,0.2,3.3,"4/23/2004",3,1.5,1.3,"5/22/2004"),nrow=4,ncol=4,byrow=TRUE)
data1<-data.frame(data1)
names(data1)<-c("areaid","x","y","date")
data1

   areaid   x   y  date
1  1 1.2 1.3 3/23/2004
2  1 1.5 2.3 3/22/2004
3  2 0.2 3.3 4/23/2004
4  3 1.5 1.3 5/22/2004
data2<-matrix(data=c(1,1.22,1.32,1,  1.53,  2.34,1,  1.21,  1.37,1,  1.52,
2.35,2,  0.21,  3.33,2,  0.23,  3.35,3,  1.57, 1.31,3,  1.59,
1.33),nrow=8,ncol=3,byrow=TRUE)
data2<-data.frame(data2)
names(data2)<-c("areaid","x1","y1")
data2

   areaid x1   y1
1  1 1.22 1.32
2  1 1.53 2.34
3  1 1.21 1.37
4  1 1.52 2.35
5  2 0.21 3.33
6  2 0.23 3.35
7  3 1.57 1.31
8  3 1.59 1.33
  Explains the two data. You can treat data1 as case dataset and data2 as
control dataset,respectively.Note th number of recodes for data2 are 2 times
as that of data1 for each records,something like 1:2 matched case-control
study design. I hope to merge data1 and data2. Take areaid=1 as an example.
>From the two dataset, we can see that data1 has two points(x,y) in areaid=1,
and data2 has four points (x1,y1) in areaid=1. Each record in data1 will
have two matched records in data2.I want to randomly select 1/2 points of
areaid=1 in data2 to link the one record of areaid=1 in the data1, and the
other 1/2 points of areaid=1 in data2 to link the other record of areaid=1
in the data1.Actually,the number of records in the same areaid will be over
2 in the actual dataset. This is only an example to explain the problem.
For the cases of areaid=2 or 3,they are a little easier than areaid=1
because there are only one value in data1.
  The final results are something like the following dataset.
areaid x1 y1date x  y
1  1.22  1.32  3/23/2004   1.2  1.3
1  1.53  2.34  3/22/2004   1.2  1.3
1  1.21  1.37  3/23/2004   1.5  2.3
1  1.52  2.35  3/22/2004   1.5  2.3
2  0.21  3.33  4/23/2004   0.2  3.3
2  0.23  3.35  4/23/2004   0.2  3.3
3  1.57  1.31  5/22/2004   1.5  1.3
3  1.59  1.33  5/22/2004   1.5  1.3

   Any suggestions or help are greatly appreciated.
  Thanks a lot.

[[alternative HTML version deleted]]

__
R-help@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.