[R] conversion of data structure between R and Perl

2008-08-27 Thread kevinchang

Dear R users,

I am trying to call a Perl subroutine from R . The subroutine returns an
arrray contaning three elements wihch are all strings. But the calling in R 
return an integer which is 0. I have no idea how this could happen. Maybe
becasue I shouldn't use system() in R or I should load a particular package
for my R in windows. Please help 

---
the perl subroutine in presentPerformance.pl

sub findAccuracy{
while(defined($filename=glob("*.log"))){

open(WORDLIST , $filename)||die("can't open the file!");
while($line=){

if ($line=~m/accuracy/){
  $line=~s/-accuracy://;
   
@temp=split(" ",$line);
$temp[0]=~s/\%//; 
$temp[2]=~s/\%//;  
@accInfoList=($temp[0],$temp[2],$filename);

}
   
}   


}
return(@accInfoList)

}


findAccuracy();

The R code 

> class(system("perl presentPerformance.pl"))
[1] "integer"




regard,
Shu-Kai Chang
-- 
View this message in context: 
http://www.nabble.com/conversion-of-data-structure-between-R-and-Perl-tp19189221p19189221.html
Sent from the R help mailing list archive at Nabble.com.

__
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] locate substring in the string it belong to

2009-07-20 Thread kevinchang

Hi R users,


I am trying generate the indices for locating a in the string it come from.
Given the length of the string, it will take too long using the combn() for
further comparison. I am wondering if R has any built-in function for this
purpose.

To make it concrete:

this.substring="cc"

this.string="ccc" 

start.location=1,2
end.location=2,3 

Thanks in advance, 
Kevin





-- 
View this message in context: 
http://www.nabble.com/locate-substring-in-the-string-it-belong-to-tp24565937p24565937.html
Sent from the R help mailing list archive at Nabble.com.

__
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] combine venn diagram and pie chart

2009-08-02 Thread kevinchang

Hi R users,

 I am wondering if it there is R's function that can help  integrate venn
diagram and pie chart to compare two related datasets. 

I know the package limma has something built-in for making venn diagram, but
I guess it would be very painful to use line and text to specify the
proportions in the fashion of pie chart . 


Thanks in advance,
Kevin Chang
-- 
View this message in context: 
http://www.nabble.com/combine-venn-diagram-and--pie-chart-tp24784565p24784565.html
Sent from the R help mailing list archive at Nabble.com.

__
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] layout of igraph

2009-02-26 Thread kevinchang

Dear R users, 

I am trying to draw a network using igraph package. I intend to place the
hub nodes (the ones with the relatively more connection with other nodes) in
the center of the graph.  Also, the graph need to be in the fashion that the
higher the correlation between two nodes is , the closer the two nodes will
be.  Is there any layout that can help or any other way to do this?  

Thanks in advance. 
Shukai 
-- 
View this message in context: 
http://www.nabble.com/layout-of-igraph-tp6348p6348.html
Sent from the R help mailing list archive at Nabble.com.

__
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] layout of igraph

2009-02-26 Thread kevinchang

Thanks Gabor's fast reply. 

In my research, every node has it's own vector of scores. So I can compute
correlation between every pair of nodes. I used the width and color of the
edge for this purpose. But visualizing the correlations by distance may be
clearer. 

Best,
Shukai


Gábor Csárdi-2 wrote:
> 
> Shukai,
> 
> the force based layout algorithms (layout.drl,
> layout.fruchterman.reingold, layout.graphopt, layout.kamada.kawai) are
> likely to do this; although they are not explicitly required to place
> hubs in the center, usually they do.
> 
> I am not sure what is the "correlation between two nodes". You mean
> that the graph is weighted?
> 
> If you have a small graph, then you can refine the layout
> interactively by using 'tkplot'.
> 
> Gabor
> 
> On Thu, Feb 26, 2009 at 4:20 PM, kevinchang  wrote:
>>
>> Dear R users,
>>
>> I am trying to draw a network using igraph package. I intend to place the
>> hub nodes (the ones with the relatively more connection with other nodes)
>> in
>> the center of the graph.  Also, the graph need to be in the fashion that
>> the
>> higher the correlation between two nodes is , the closer the two nodes
>> will
>> be.  Is there any layout that can help or any other way to do this?
>>
>> Thanks in advance.
>> Shukai
>> --
>> View this message in context:
>> http://www.nabble.com/layout-of-igraph-tp6348p6348.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> 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.
>>
> 
> 
> 
> -- 
> Gabor Csardi  UNIL DGM
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/layout-of-igraph-tp6348p6854.html
Sent from the R help mailing list archive at Nabble.com.

__
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] save the layout using igraph

2009-03-03 Thread kevinchang

Hi R users,

I am using built-in functions in  igraph package to draw networks . I need
to compare several network with exactly the same structure but with edge
hightlighted differently.  I am wondering if there is a way to save the
layout so that every graph will look the same as each other except for the
colors of edges. Or is there any parameter I can set for this purpose??

Thanks in advance, 
Shukai
-- 
View this message in context: 
http://www.nabble.com/save-the-layout-using-igraph-tp22316155p22316155.html
Sent from the R help mailing list archive at Nabble.com.

__
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] function for special matrix design

2007-10-01 Thread kevinchang

Hi All,

I am trying to make a matrix with a particular value for all the elements
above and including diagonal and another particular value for all the
elements below diagonal. Obviously , Matrix function in Matrix package does
not work since it only allow filling by either row or column. So I am
wondering if there is a built-in function allowing me to do this ? please
help. Thanks



-- 
View this message in context: 
http://www.nabble.com/function-for-special-matrix-design-tf4549437.html#a12982709
Sent from the R help mailing list archive at Nabble.com.

__
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] inverse of matrix made by low.tri function

2007-10-03 Thread kevinchang

Hi all,


I am using R trying to get a inverse matrix of (X^T)X , but I keep getting
the error 
message like: no b argument and no default value for sprintf(gettext(fmt,
domain = domain), ...) .

# my code

X<-Matrix(rep(1,500),100,5)
X[lower.tri(X)]<-1-10^-7
XtX<- t(X)%*% X
XtXu<-lu(XtX)
InverseXtX<-solve(XtXu)

-

The cause suggested for this error is that the lower.tri function returns a
matrix of logicals. If so, is trying to fix this by using sprintf function a
good idea ? Or is there is any alternative way to get the inverse matrix?
Please help. Thanks

-- 
View this message in context: 
http://www.nabble.com/inverse-of-matrix-made-by-low.tri-function-tf4562543.html#a13021480
Sent from the R help mailing list archive at Nabble.com.

__
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] Newton method iteration problem

2007-10-26 Thread kevinchang

Hi all,

I am coding for finding the root of f(x)= phi(x) -alpha  where phi(x) is the
cumulative density function and alpha is constant . The problem right now is
I can't get the "initialX" representing the root out of the while loop when
ending , it seems to me it disappear when the loop ends accroding to the
error message. I need help . Please suggest the cause  or solution to this
problem. Thanks. 

# code 

#generate target function (phi(x)-alpha) (allow input x and alpha)
target<-function(x,alpha){
pnorm(x)-alpha 
}


#generate the first derivative of the of the target function 
firstDerivative<-function(x){
exp(-(x^2)/2)/sqrt(2*pi)
}

# Finding the root by Newton method 
rootFinding<-function(initialX,setAlpha){
while(target(initialX,setAlpha)!=0){
initialX<-initialX-(target(initialX,setAlpha)/firstfirstDerivative(initialX)
}
initialX
}


-- 
View this message in context: 
http://www.nabble.com/Newton-method-iteration-problem-tf4701085.html#a13439031
Sent from the R help mailing list archive at Nabble.com.

__
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] Newton method iteration problem

2007-10-27 Thread kevinchang

Thanks Chales for pointing out the errors.
I fixed an errorr and R accepted my "rootFinding" code. 
But the problem right now is that my code will work only if the intialX
value is close enough to the solution.
Otherwise, R says there is missing true/false value in the codition test of
while loop.  I can't figure out what happens. Some advice , please?? 

#generate target function (phi(x)-alpha) (allow input x and alpha)
target<-function(x,alpha){
pnorm(x)-alpha 
}

#generate the first derivative of the of the target function 
firstDerivative<-function(x){
exp(-(x^2)/2)/sqrt(2*pi)
}

# Finding the root by Newton method 
rootFinding<-function(initialX,setAlpha,maxIter){
while((target(initialX,setAlpha)!=0) && maxIter>0){
initialX<-initialX-(target(initialX,setAlpha)/firstDerivative(initialX))
maxIter<-maxIter-1
}
initialX
}











Charles C. Berry wrote:
> 
> On Fri, 26 Oct 2007, kevinchang wrote:
> 
>>
>> Hi all,
>>
>> I am coding for finding the root of f(x)= phi(x) -alpha  where phi(x) is
>> the
>> cumulative density function and alpha is constant . The problem right now
>> is
>> I can't get the "initialX" representing the root out of the while loop
>> when
>> ending , it seems to me it disappear when the loop ends accroding to the
>> error message. I need help . Please suggest the cause  or solution to
>> this
>> problem. Thanks.
> 
> Learn to type without making errors? Learn to format (space and indent) 
> your code so errors will be more obvious to you??
> 
> Your code worked for me once I corrected the typos and syntax errors.
> 
> It even agrees with qnorm( setAlpha ).
> 
> If all you want is root finding capability, I suggest you see
> 
> ?uniroot
> 
> and friends.
> 
> HTH,
> 
> Chuck
> 
>>
>> # code
>>
>> #generate target function (phi(x)-alpha) (allow input x and alpha)
>> target<-function(x,alpha){
>> pnorm(x)-alpha
>> }
>>
>>
>> #generate the first derivative of the of the target function
>> firstDerivative<-function(x){
>> exp(-(x^2)/2)/sqrt(2*pi)
>> }
>>
>> # Finding the root by Newton method
>> rootFinding<-function(initialX,setAlpha){
>> while(target(initialX,setAlpha)!=0){
>> initialX<-initialX-(target(initialX,setAlpha)/firstfirstDerivative(initialX)
>> }
>> initialX
>> }
>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Newton-method-iteration-problem-tf4701085.html#a13439031
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> 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.
>>
> 
> Charles C. Berry(858) 534-2098
>  Dept of Family/Preventive
> Medicine
> E mailto:[EMAIL PROTECTED]UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Newton-method-iteration-problem-tf4701085.html#a13442728
Sent from the R help mailing list archive at Nabble.com.

__
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] flops calculation

2007-10-28 Thread kevinchang

Hi all,

Since proc.time return three different kind of times (user, system and
elapsed) , I am wondering which one is right for calculating flops. In New S
Language (Becker et. al. ) , it seems to be the user because " the user time
measures the processor time used in S  and the system time measures the
operating system in response to S's request". But in R Help ,  system time
sounds better as " The first two entries(referred to user and system time
respectively) are the total user and system CPU times of the current R
process and any child processes on which it has waited".  Please help .
Thanks.





-- 
View this message in context: 
http://www.nabble.com/flops-calculation-tf4708965.html#a13459745
Sent from the R help mailing list archive at Nabble.com.

__
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] alternative way to loop

2007-09-11 Thread kevinchang

I heard that if-loop may result in errors if we are going to loop for a lot
of times. And sum() can be the alternative way to do this kind of  hugbe
looping. But I haven't figure out how . Can someone please give me an
concrete example of using sum() for this purpose? 
-- 
View this message in context: 
http://www.nabble.com/alternative-way-to-loop-tf4422299.html#a12613696
Sent from the R help mailing list archive at Nabble.com.

__
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] rearrange problem

2007-09-13 Thread kevinchang

Hi All,

I am trying to rearrange alphabetically each element in a character vector.
ex: say the first element in the vector is "cba", and my goal is to turn it
into "abc". The suggested function to use is sort(). But it turns out that
sort doesn't work at the level of element. So I am wondering that if there
is an alternative function for this purpose. Please help me out . Thanks. 
-- 
View this message in context: 
http://www.nabble.com/rearrange-problem-tf4434906.html#a12652394
Sent from the R help mailing list archive at Nabble.com.

__
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] locate word in vector

2007-09-14 Thread kevinchang

Hey All,


I am wondering if there is a built-in function allowing us to locate a
particular word in a character vector.

ex: vector a

a
[1] "superman"  "xamn"  "spiderman" "superman"  "superman"  "xman" 
[7] "spiderman"

Is there any built-in function that can show "superman" are the first,
fourth and fifith element in "a"? Please help me out. Thanks. 


-- 
View this message in context: 
http://www.nabble.com/locate-word-in-vector-tf4445881.html#a12685567
Sent from the R help mailing list archive at Nabble.com.

__
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] starting with a capital letter

2007-09-15 Thread kevinchang

Hi everyone,

I am wondering if there is any built-in funcion that can determine whether
words in a character vector start with a captial letter or not. Help,
please. Thanks.
-- 
View this message in context: 
http://www.nabble.com/starting-with-a-capital-letter-tf4447302.html#a12689105
Sent from the R help mailing list archive at Nabble.com.

__
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] naming columns of data frame

2007-09-15 Thread kevinchang

Hey,

I am trying to make a data frame and the name of a column is composed of a
number, a dot, and a word, such as "1.whatever". But I always get this error
message:"syntax error, unexpected SYMBOL, expecting ',' in:" while printing
data frame out . When I rename the column with purely letter, everything
works fine. Some suggestion about the cause/ solution ?? Thanks.
-- 
View this message in context: 
http://www.nabble.com/naming-columns-of-data-frame-tf4449324.html#a12694795
Sent from the R help mailing list archive at Nabble.com.

__
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] stalled loop

2007-09-16 Thread kevinchang

Hi, 

The loop I wrote executes correctly but  is stalled seriously. Is there a
way to hasten execution without coming up with a  brand new algorithm ? 
please help. Thanks.
-- 
View this message in context: 
http://www.nabble.com/stalled-loop-tf4451301.html#a12699524
Sent from the R help mailing list archive at Nabble.com.

__
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] stalled loop

2007-09-16 Thread kevinchang

Hey everyone,

The code I wrote executes correctly but  is stalled seriously. Is there a
way to hasten execution without coming up with a  brand new algorithm
?please help. Thanks a lot for your time.


#a simplified version of the code

a<-c("superman" , "xman" , "spiderman" ,"wolfman" ,"mansuper","manspider" )
b<-sapply(a,function(.srt){paste(sort(strsplit(.srt,'')[[1]]),
collapse="")})
c<-NA 
for(i in 1:length(b)) {
if(length(which(b==b[i]))>1)
c[i]<-b[i]
}
c<-c[!is.na(c)]
# But if my get the volumne of "a" up to about 15 words , the loop will
work incredibly slowly.

-- 
View this message in context: 
http://www.nabble.com/stalled-loop-tf4456879.html#a12708590
Sent from the R help mailing list archive at Nabble.com.

__
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.