Re: [R] Removing named objects using rm(..)

2012-12-11 Thread Martin Maechler
> "WR" == Worik R 
> on Tue, 11 Dec 2012 19:59:58 +1300 writes:

WR> On Tue, Dec 11, 2012 at 7:49 PM, Jeff Newmiller 
wrote:
>> What about putting your objects in a list, which does not have the search
>> through parents semantics?
>> 
---
>> 
>> 

>>> 
>>> You may find it more reliable to define an environment in which you
>>> will be storing your data (perhaps globalenv(), perhaps something
>> created
>>> by new.env())  and then testing for existence of a dataset by a given
>> name
>>> in that environment.

WR> Both  interesting ideas.

Well,  Do follow only Bill Dunlap's.
Using environments is *the way* to add and remove variables,


WR> Turns out I can remove 'timeSeries' so that  solves my problem but does 
not
WR> answer my questions.

When are taught to use  get(),  and it does not immediately do
what you want,
why not read its help page and look at the examples on that help
page ??

[Hint:  The optional argument you want start with 'in..']

Martin

__
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] How do you use agrep inside a loop

2012-12-11 Thread surekha nagabhushan
Thank you for that Pascal.

I changed this bit to the following:

result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
  for(j in i+1:length(test1))
  {
  result[[i]][j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value =
TRUE, max.distance = 0.1)
  }
}

And now I get the error - Error in result[[i]][j - i] <- agrep(test1[i],
test1[j], ignore.case = TRUE,  :
  replacement has length zero

What does this mean?

On Tue, Dec 11, 2012 at 1:24 PM, Pascal Oettli  wrote:

> Hi,
>
> There is a mistake in the first line. It should be:
> > for(i in 1:(length(test1)-1))
>
> Regards,
> Pascal
>
>
> Le 11/12/2012 16:01, surekha nagabhushan a écrit :
>
>> Hi all.
>>
>> This is my first message at R-help...so I'm hoping I have some beginner's
>> luck and get some good help for my problem!
>>
>> FYI I have just started using R recently so my knowledge of R is pretty
>> preliminary.
>>
>> Okay here is what I need help with - I need to know how to use agrep in a
>>   for loop.
>>
>> I need to compare elements of a vector of names with other elements of the
>> same vector.
>>
>> However if I use something like this:
>>
>> for(i in 1:length(test1)-1)
>> {
>>for(j in i+1:length(test1))
>>{
>>result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE, value =
>> TRUE, max.distance = 0.1)
>>}
>>
>> }
>>
>> I get an error message saying - invalid 'pattern' argument. -* Error in
>>
>> agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance =
>> 0.1) : *
>> *  invalid 'pattern' argument*
>>
>>
>> Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new
>> Mumbai",
>> "Thana", "Surekha", "Thane(w)", "surekhaN")
>>
>> This is the first time I'm using agrep, I do not understand how it works
>> fully...
>>
>> Kindly help...
>>
>> Thank you.
>>
>> Su.
>>
>> [[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.
>>
>>

[[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] Writing escaped unicode

2012-12-11 Thread Jan T Kim
On Mon, Dec 10, 2012 at 11:46:40PM -0500, David Kulp wrote:
> I'd like to write unicode strings using the "\u" escape syntax.  According to 
> the documentation, print.default or encodeString will escape unicode using 
> the \u convention.  In practice, I can't make it work.
> 
> > b="Unicode character: \ufffd"
> > print.default(b)
> [1] "Unicode character: ???"
> > encodeString(b)
> [1] "Unicode character: ???"
> 
> I want to write the string back out in the same escape formatting as I read 
> it in.  This is because I'm interfacing with some Ruby code that requires 
> unicode to be in this escaped format.

as I read the documentation, encodeString escapes control characters,
but not "unicode characters". The notion of a "unicode character" is
not entirely well defined, considering that the very mission of the
unicode consortium is to make sure that there are no non-unicode
characters...  ;-)

>From this it follows that replacing all characters with their \u
representation, e.g. by

paste(sprintf("\\u%04x", utf8ToInt(b)), collapse = "");

should work with the Ruby client you try to talk to. Obviously, this
bloats the string rather more than necessary (particularly if most of
the characters are in the ASCII range), but if the volume you're
piping into the client is small, this may be good enough.

Best regards, Jan
-- 
 +- Jan T. Kim ---+
 | email: jtt...@gmail.com|
 | WWW:   http://www.jtkim.dreamhosters.com/  |
 *-=<  hierarchical systems are for files, not for humans  >=-*

__
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] How do you use agrep inside a loop

2012-12-11 Thread Pascal Oettli

Hello,

Probably because 'result' doesn't have the expected size/number of 
dimension. How do you create it?


Regards,
Pascal


Le 11/12/2012 19:46, surekha nagabhushan a écrit :

Thank you for that Pascal.

I changed this bit to the following:

result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
   for(j in i+1:length(test1))
   {
   result[[i]][j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE,
value = TRUE, max.distance = 0.1)
   }
}

And now I get the error - Error in result[[i]][j - i] <- agrep(test1[i],
test1[j], ignore.case = TRUE,  :
   replacement has length zero

What does this mean?

On Tue, Dec 11, 2012 at 1:24 PM, Pascal Oettli mailto:kri...@ymail.com>> wrote:

Hi,

There is a mistake in the first line. It should be:
 > for(i in 1:(length(test1)-1))

Regards,
Pascal


Le 11/12/2012 16:01, surekha nagabhushan a écrit :

Hi all.

This is my first message at R-help...so I'm hoping I have some
beginner's
luck and get some good help for my problem!

FYI I have just started using R recently so my knowledge of R is
pretty
preliminary.

Okay here is what I need help with - I need to know how to use
agrep in a
   for loop.

I need to compare elements of a vector of names with other
elements of the
same vector.

However if I use something like this:

for(i in 1:length(test1)-1)
{
for(j in i+1:length(test1))
{
result[[i]][j] <- agrep(test1[i], test1[j], ignore.case =
TRUE, value =
TRUE, max.distance = 0.1)
}

}

I get an error message saying - invalid 'pattern' argument. -*
Error in

agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE,
max.distance =
0.1) : *
*  invalid 'pattern' argument*


Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane",
"Vashi,new Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")

This is the first time I'm using agrep, I do not understand how
it works
fully...

Kindly help...

Thank you.

Su.

 [[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-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] Renaming column names according to another dataframe

2012-12-11 Thread Johannes Radinger
Hi,

I've got a dataframe having a code as column name.
Addtionally I have another dataframe with a two columns (and lots of
rows), the first
containing the code and the second some Text (real name).

Now I'd like to use the information (pairs of code and name) of the
second dataframe to rename all the columnnames in the first dataframe.
How is it possible to achieve that?

Here a small example of the two dataframes:

df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
df_names <- data.frame(code=c("A","B","C","D","E"),name=c("Col A","Col
B","Col C","Col D","Col E"))

/j

__
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] How do you use agrep inside a loop

2012-12-11 Thread Rui Barradas

Hello,

And another error in line 2. It should be

for(j in (i+1):length(test1))


Hope this helps,

Rui Barradas

Em 11-12-2012 07:54, Pascal Oettli escreveu:

Hi,

There is a mistake in the first line. It should be:
> for(i in 1:(length(test1)-1))

Regards,
Pascal


Le 11/12/2012 16:01, surekha nagabhushan a écrit :

Hi all.

This is my first message at R-help...so I'm hoping I have some 
beginner's

luck and get some good help for my problem!

FYI I have just started using R recently so my knowledge of R is pretty
preliminary.

Okay here is what I need help with - I need to know how to use agrep 
in a

  for loop.

I need to compare elements of a vector of names with other elements 
of the

same vector.

However if I use something like this:

for(i in 1:length(test1)-1)
{
   for(j in i+1:length(test1))
   {
   result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE, 
value =

TRUE, max.distance = 0.1)
   }

}

I get an error message saying - invalid 'pattern' argument. -* Error in
agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, 
max.distance =

0.1) : *
*  invalid 'pattern' argument*

Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new 
Mumbai",

"Thana", "Surekha", "Thane(w)", "surekhaN")

This is the first time I'm using agrep, I do not understand how it works
fully...

Kindly help...

Thank you.

Su.

[[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-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-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] questions on French characters in plot

2012-12-11 Thread Milan Bouchet-Valat
Le mardi 11 décembre 2012 à 01:10 +0100, Richard Zijdeman a écrit :
> Dear all,
> 
> I have imported a dataset from Stata using the foreign package. The
> original data contain French characters such as  and  .
> After importing, string variables containing names of French
> departments have changed. E.g. Ardche became Ard\x8fche. I would like
> to ask how I could plot these changed strings, since now the strings
> with special characters fail to be printed in the plot (either using
> plot() or ggplot2()).
> 
> I have googled for solutions, but actually find it hard to determine
> whether I should change my R setup or should read in the data in a
> different way. Since I work on a mac I changed my local according to
> the R for Mac OS X FAQ, chapter 9.  Below is some info on my setup and
> code and output on what works for me and what does not. Thank you in
> advance for you comments.
Accentuated characters should work fine on a machine using a UTF-8
locale as yours. I think the problem is that the imported data uses
ISO8859-15 or UTF-16, not UTF-8.

I have no idea whether .dta files specify an encoding or not, but I
think you can convert them in R by calling
iconv(department, "ISO-8859-15", "UTF-8")
or
iconv(department, "UTF-16", "UTF-8")

> Best,
> 
> Richard
> 
> #--
> rm(list=ls())
> sessionInfo()
> # R version 2.15.2 (2012-10-26)
> # Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> #
> # locale:
> # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> # creating variables
> department  <- c("Nord","Paris","Ard\x8fche")
\x8 does not correspond to "è" AFAIK. In ISO8859-1 and -15 and UTF-16,
it's \xE8 ("\uE8" in R).

In UTF-8, it's C3 A8, "\303\250" in R.

> department2 <- c("Nord", "Paris", "Ardche")
> n   <- c(2,4,1)
> 
> # creating dataframes
> df  <- data.frame(department,n)
> df2 <- data.frame(department2,n)
> 
> department
> # [1] "Nord"   "Paris"  "Ard\x8fche"
> department2
> # [1] "Nord""Paris"   "Ardche"
> 
> plot(df) # fails to show the text "Ardche"
> plot(df2) # shows text "Ardche"
> 
> # EOF
>   [[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-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] Latitudinal mean of values in a data frame

2012-12-11 Thread Swagath Navin

Dear all,

I have a big file containing latitude points(-10 to 80) and 
corresponding values.

Example data

Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 
69.53746, 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 
70.00106, 70.00295, 70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 
70.01049, 70.01053, 70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 
70.01646, 70.01983, 70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 
70.02856, 70.0291, 70.02983, 70.03091, 70.03267, 70.03423)


Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 
0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 
0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 
0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 0.14388486, 
0.19098477, 0.17252013, 0.12965086, 0.12256515, 0.18159349, 0.15608113, 
0.18742996, 0.13858418, 0.16865459, 0.19058037, 0.12531143, 0.19189732, 
0.12019097, 0.1790819, 0.15086053, 0.18607724,  0.13330366)


dframe=data.frame(Lat, Value)

i would like to find latitudinal mean such that my output looks like the 
below:


Lat Value
69 0.18
70 0.16

I am thankful for any ideas how to perform this or which function i 
should look into.


Thanks a lot for your time,
Cheers,
Navin

__
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] How do you use agrep inside a loop

2012-12-11 Thread surekha nagabhushan
Pascal,

result_vector <- vector()
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
  for(j in (i+1):length(test1))
  {
  result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
= TRUE, max.distance = 0.1)
  }
  result[[i]]<- result_vector
}

I'm not sure what the problem is with the dimension/length of result which
is a list. But I just use the second line: result <- vector("list",
(length(test1)-1))

What am I missing?

Thank you Rui Barradas.

On Tue, Dec 11, 2012 at 4:25 PM, Rui Barradas  wrote:

> Hello,
>
> And another error in line 2. It should be
>
> for(j in (i+1):length(test1))
>
>
> Hope this helps,
>
> Rui Barradas
>
> Em 11-12-2012 07:54, Pascal Oettli escreveu:
>
>  Hi,
>>
>> There is a mistake in the first line. It should be:
>> > for(i in 1:(length(test1)-1))
>>
>> Regards,
>> Pascal
>>
>>
>> Le 11/12/2012 16:01, surekha nagabhushan a écrit :
>>
>>> Hi all.
>>>
>>> This is my first message at R-help...so I'm hoping I have some beginner's
>>> luck and get some good help for my problem!
>>>
>>> FYI I have just started using R recently so my knowledge of R is pretty
>>> preliminary.
>>>
>>> Okay here is what I need help with - I need to know how to use agrep in a
>>>   for loop.
>>>
>>> I need to compare elements of a vector of names with other elements of
>>> the
>>> same vector.
>>>
>>> However if I use something like this:
>>>
>>> for(i in 1:length(test1)-1)
>>> {
>>>for(j in i+1:length(test1))
>>>{
>>>result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
>>> =
>>> TRUE, max.distance = 0.1)
>>>}
>>>
>>> }
>>>
>>> I get an error message saying - invalid 'pattern' argument. -* Error in
>>> agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance
>>> =
>>> 0.1) : *
>>> *  invalid 'pattern' argument*
>>>
>>> Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new
>>> Mumbai",
>>> "Thana", "Surekha", "Thane(w)", "surekhaN")
>>>
>>> This is the first time I'm using agrep, I do not understand how it works
>>> fully...
>>>
>>> Kindly help...
>>>
>>> Thank you.
>>>
>>> Su.
>>>
>>> [[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-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.
>>
>
>

[[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] How do you use agrep inside a loop

2012-12-11 Thread Pascal Oettli

Hello,

Right, I didn't notice. Apologies.

Pascal


Le 11/12/2012 19:55, Rui Barradas a écrit :

Hello,

And another error in line 2. It should be

for(j in (i+1):length(test1))


Hope this helps,

Rui Barradas

Em 11-12-2012 07:54, Pascal Oettli escreveu:

Hi,

There is a mistake in the first line. It should be:
> for(i in 1:(length(test1)-1))

Regards,
Pascal


Le 11/12/2012 16:01, surekha nagabhushan a écrit :

Hi all.

This is my first message at R-help...so I'm hoping I have some
beginner's
luck and get some good help for my problem!

FYI I have just started using R recently so my knowledge of R is pretty
preliminary.

Okay here is what I need help with - I need to know how to use agrep
in a
  for loop.

I need to compare elements of a vector of names with other elements
of the
same vector.

However if I use something like this:

for(i in 1:length(test1)-1)
{
   for(j in i+1:length(test1))
   {
   result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE,
value =
TRUE, max.distance = 0.1)
   }

}

I get an error message saying - invalid 'pattern' argument. -* Error in
agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE,
max.distance =
0.1) : *
*  invalid 'pattern' argument*

Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new
Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")

This is the first time I'm using agrep, I do not understand how it works
fully...

Kindly help...

Thank you.

Su.

[[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-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-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] How do you use agrep inside a loop

2012-12-11 Thread Rui Barradas

Hello,

See if this is it. You must reinitialize 'result_vector' just before the 
loop that constructs it.



test1 <- c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")

result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1)){
result_vector <- vector()
for(j in (i+1):length(test1)){
tmp <- agrep(test1[i], test1[j],
ignore.case = TRUE, value = TRUE,
max.distance = 0.1)
if(length(tmp) > 0) result_vector[j-i] <- tmp
}
result[[i]] <- result_vector
}
result


Hope this helps,

Rui Barradas
Em 11-12-2012 11:23, surekha nagabhushan escreveu:

Pascal,

result_vector <- vector()
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
   for(j in (i+1):length(test1))
   {
   result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
= TRUE, max.distance = 0.1)
   }
   result[[i]]<- result_vector
}

I'm not sure what the problem is with the dimension/length of result which
is a list. But I just use the second line: result <- vector("list",
(length(test1)-1))

What am I missing?

Thank you Rui Barradas.

On Tue, Dec 11, 2012 at 4:25 PM, Rui Barradas  wrote:


Hello,

And another error in line 2. It should be

for(j in (i+1):length(test1))


Hope this helps,

Rui Barradas

Em 11-12-2012 07:54, Pascal Oettli escreveu:

  Hi,

There is a mistake in the first line. It should be:

for(i in 1:(length(test1)-1))

Regards,
Pascal


Le 11/12/2012 16:01, surekha nagabhushan a écrit :


Hi all.

This is my first message at R-help...so I'm hoping I have some beginner's
luck and get some good help for my problem!

FYI I have just started using R recently so my knowledge of R is pretty
preliminary.

Okay here is what I need help with - I need to know how to use agrep in a
   for loop.

I need to compare elements of a vector of names with other elements of
the
same vector.

However if I use something like this:

for(i in 1:length(test1)-1)
{
for(j in i+1:length(test1))
{
result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
=
TRUE, max.distance = 0.1)
}

}

I get an error message saying - invalid 'pattern' argument. -* Error in
agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance
=
0.1) : *
*  invalid 'pattern' argument*

Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new
Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")

This is the first time I'm using agrep, I do not understand how it works
fully...

Kindly help...

Thank you.

Su.

 [[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-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-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] Renaming column names according to another dataframe

2012-12-11 Thread Anthony Damico
df <- data.frame(A=(1:10),B=(1:10),C=(1:10))

# my changes to show that order doesn't matter
df_names <- data.frame(code=c("C","A","D","E","B"),name=c("Col C","Col
A","Col D","Col E","Col B"))

names( df ) <- df_names[ match( names( df ) , df_names[ , 'code' ] ) ,
'name' ]

for more detail see
?match



On Tue, Dec 11, 2012 at 5:55 AM, Johannes Radinger <
johannesradin...@gmail.com> wrote:

> Hi,
>
> I've got a dataframe having a code as column name.
> Addtionally I have another dataframe with a two columns (and lots of
> rows), the first
> containing the code and the second some Text (real name).
>
> Now I'd like to use the information (pairs of code and name) of the
> second dataframe to rename all the columnnames in the first dataframe.
> How is it possible to achieve that?
>
> Here a small example of the two dataframes:
>
> df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
> df_names <- data.frame(code=c("A","B","C","D","E"),name=c("Col A","Col
> B","Col C","Col D","Col E"))
>
> /j
>
> __
> 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.
>

[[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] How do you use agrep inside a loop

2012-12-11 Thread surekha nagabhushan
Rui,

I have initialized it...doesn't seem to help...

result_vector <- vector()
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
  for(j in (i+1):length(test1))
  {
  result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
= TRUE, max.distance = 0.1)
  }
  result[[i]]<- result_vector
}

whenever agrep does not find a match it returns character(0), length zero,
do you suppose it has anything to do with that?

Thank you.

On Tue, Dec 11, 2012 at 5:13 PM, Rui Barradas  wrote:

> Hello,
>
> See if this is it. You must reinitialize 'result_vector' just before the
> loop that constructs it.
>
>
> test1 <- c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new Mumbai",
>
> "Thana", "Surekha", "Thane(w)", "surekhaN")
>
> result <- vector("list", (length(test1)-1))
> for(i in 1:(length(test1)-1)){
> result_vector <- vector()
> for(j in (i+1):length(test1)){
> tmp <- agrep(test1[i], test1[j],
>
> ignore.case = TRUE, value = TRUE,
> max.distance = 0.1)
> if(length(tmp) > 0) result_vector[j-i] <- tmp
> }
> result[[i]] <- result_vector
> }
> result
>
>
>
> Hope this helps,
>
> Rui Barradas
> Em 11-12-2012 11:23, surekha nagabhushan escreveu:
>
>> Pascal,
>>
>> result_vector <- vector()
>> result <- vector("list", (length(test1)-1))
>> for(i in 1:(length(test1)-1))
>> {
>>for(j in (i+1):length(test1))
>>{
>>result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE,
>> value
>> = TRUE, max.distance = 0.1)
>>}
>>result[[i]]<- result_vector
>> }
>>
>> I'm not sure what the problem is with the dimension/length of result which
>> is a list. But I just use the second line: result <- vector("list",
>> (length(test1)-1))
>>
>> What am I missing?
>>
>> Thank you Rui Barradas.
>>
>> On Tue, Dec 11, 2012 at 4:25 PM, Rui Barradas 
>> wrote:
>>
>>  Hello,
>>>
>>> And another error in line 2. It should be
>>>
>>> for(j in (i+1):length(test1))
>>>
>>>
>>> Hope this helps,
>>>
>>> Rui Barradas
>>>
>>> Em 11-12-2012 07:54, Pascal Oettli escreveu:
>>>
>>>   Hi,
>>>
 There is a mistake in the first line. It should be:

> for(i in 1:(length(test1)-1))
>
 Regards,
 Pascal


 Le 11/12/2012 16:01, surekha nagabhushan a écrit :

  Hi all.
>
> This is my first message at R-help...so I'm hoping I have some
> beginner's
> luck and get some good help for my problem!
>
> FYI I have just started using R recently so my knowledge of R is pretty
> preliminary.
>
> Okay here is what I need help with - I need to know how to use agrep
> in a
>for loop.
>
> I need to compare elements of a vector of names with other elements of
> the
> same vector.
>
> However if I use something like this:
>
> for(i in 1:length(test1)-1)
> {
> for(j in i+1:length(test1))
> {
> result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE,
> value
> =
> TRUE, max.distance = 0.1)
> }
>
> }
>
> I get an error message saying - invalid 'pattern' argument. -* Error in
> agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE,
> max.distance
> =
> 0.1) : *
> *  invalid 'pattern' argument*
>
> Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new
> Mumbai",
> "Thana", "Surekha", "Thane(w)", "surekhaN")
>
> This is the first time I'm using agrep, I do not understand how it
> works
> fully...
>
> Kindly help...
>
> Thank you.
>
> Su.
>
>  [[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-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.


>>>
>

[[alternative HTML version deleted]]

__
R-

Re: [R] Removing named objects using rm(..)

2012-12-11 Thread Duncan Murdoch

On 12-12-10 8:46 PM, Worik R wrote:





On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch
mailto:murdoch.dun...@gmail.com>> wrote:

On 12-12-10 7:33 PM, Worik R wrote:

Let me restate my question.

Is there a straightforward way of ensuring I can use the
variable name
USDCHF?


You can use any legal variable name.  The only risk is that you will
overwrite some other variable that you created.  You can't overwrite
variables from packages.  (You might mask them, but they are still
accessible using the :: notation.  E.g. after you set

USDCHF <- NULL


Exactly.  I got around this by assigning NULL to the variable names that
I would have deleted.  Then instead of testing for existence I tested
for NULL.


I think you are very confused.  What are you "getting around" by doing 
this?



you can still access the one in timeSeries using

timeSeries::USDCHF


Christ.  That is what I wanted to delete.  I read the scoping section of
R-Lang (again) and nothing  I could see prepared me for the shock of...

 > library(timeSeries)
 > nrow(USDCHF)
[1] 62496
 > rm(USDCHF)
Warning message:
In rm(USDCHF) : object 'USDCHF' not found
 > nrow(USDCHF)
[1] 62496


The message from rm was that USDCHF did not exist.  But I can still
access its properties with nrow.


It doesn't exist in the location where you asked to do the remove, i.e. 
in the global environment.




This is very broken.  I would not have believed I would see that in the
21st century with a modern language.  (Oh wait, there is Javascript and
PHP, so in comparison R is not that broken)


I don't know what you think you are seeing, but in this respect R is not 
particularly broken.



I am not new to R, I have been (mis)using it for 5 years.  I love
aspects of R, but this and a few other things (lack of debugging support
and ignoring the "principle of least surprise" are two biggies) are very
frustrating.  Without debugging support or more help from the compiler
(like a "cannot rm EURCHF" message instead of a lie) R causes as many
problems as it solves.


You said "remove USDCHF from the global environment", and R said "object 
'USDCHF' not found".  How is that a lie?  It was never there.


Duncan Murdoch




Sigh.  Thanks for the help.

Worik







__
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] Removing named objects using rm(..)

2012-12-11 Thread Duncan Murdoch

On 12-12-11 12:42 AM, Worik R wrote:


You may find it more reliable to define an environment in which you
will be storing your data (perhaps globalenv(), perhaps something created
by new.env())  and then testing for existence of a dataset by a given name
in that environment.



I did that.

PAIR.ENV <- new.env()

get("USDCHF", env=PAIR.ENV)

returns trhe USDCHF defined in timeSeries

This is very hard!


I think if you had followed my advice (reading up on scoping) you 
wouldn't find it so hard.  new.env() creates a new environment whose 
parent (or enclosure) is globalenv().  So when you do a search in 
PAIR.ENV, you'll search there first, then in globalenv(), then in its 
parent, etc.


If you don't want this to happen, don't set globalenv() as the parent. 
emptyenv() is likely what you want instead:


PAIR.ENV <- new.env(parent=emptyenv())

means that only the objects you put there will be found.

Duncan Murdoch



Worik

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 Worik R
Sent: Monday, December 10, 2012 5:47 PM
To: Duncan Murdoch
Cc: r-help
Subject: Re: [R] Removing named objects using rm(..)

On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch
wrote:


On 12-12-10 7:33 PM, Worik R wrote:


Let me restate my question.

Is there a straightforward way of ensuring I can use the variable name
USDCHF?



You can use any legal variable name.  The only risk is that you will
overwrite some other variable that you created.  You can't overwrite
variables from packages.  (You might mask them, but they are still
accessible using the :: notation.  E.g. after you set

USDCHF <- NULL



Exactly.  I got around this by assigning NULL to the variable names that

I

would have deleted.  Then instead of testing for existence I tested for
NULL.




you can still access the one in timeSeries using

timeSeries::USDCHF



Christ.  That is what I wanted to delete.  I read the scoping section of
R-Lang (again) and nothing  I could see prepared me for the shock of...


library(timeSeries)
nrow(USDCHF)

[1] 62496

rm(USDCHF)

Warning message:
In rm(USDCHF) : object 'USDCHF' not found

nrow(USDCHF)

[1] 62496


The message from rm was that USDCHF did not exist.  But I can still

access

its properties with nrow.

This is very broken.  I would not have believed I would see that in the
21st century with a modern language.  (Oh wait, there is Javascript and
PHP, so in comparison R is not that broken)

I am not new to R, I have been (mis)using it for 5 years.  I love aspects
of R, but this and a few other things (lack of debugging support and
ignoring the "principle of least surprise" are two biggies) are very
frustrating.  Without debugging support or more help from the compiler
(like a "cannot rm EURCHF" message instead of a lie) R causes as many
problems as it solves.

Sigh.  Thanks for the help.

Worik








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




[[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-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] Writing escaped unicode

2012-12-11 Thread Duncan Murdoch
On 12-12-11 5:49 AM, Jan T Kim wrote:> On Mon, Dec 10, 2012 at 
11:46:40PM -0500, David Kulp wrote:
>> I'd like to write unicode strings using the "\u" escape syntax. 
According to the documentation, print.default or encodeString will 
escape unicode using the \u convention.  In practice, I can't make it work.

>>
>>> b="Unicode character: \ufffd"
>>> print.default(b)
>> [1] "Unicode character: ???"
>>> encodeString(b)
>> [1] "Unicode character: ???"
>>
>> I want to write the string back out in the same escape formatting as 
I read it in.  This is because I'm interfacing with some Ruby code that 
requires unicode to be in this escaped format.

>
> as I read the documentation, encodeString escapes control characters,
> but not "unicode characters". The notion of a "unicode character" is
> not entirely well defined, considering that the very mission of the
> unicode consortium is to make sure that there are no non-unicode
> characters...  ;-)
>
>>From this it follows that replacing all characters with their \u
> representation, e.g. by
>
>  paste(sprintf("\\u%04x", utf8ToInt(b)), collapse = "");
>
> should work with the Ruby client you try to talk to. Obviously, this
> bloats the string rather more than necessary (particularly if most of
> the characters are in the ASCII range), but if the volume you're
> piping into the client is small, this may be good enough.

It's not too hard to do this only for the ones that need escaping.  If 
you want to convert control characters, this works:


code <- utf8ToInt(b)
paste( ifelse(31 < code & code < 128, intToUtf8(code, multiple=TRUE),
  sprintf("\\u%04x", code)),
   collapse=TRUE)

(And David should remember to use cat() or similar to print it, or the 
backslashes in the strings will appear to be doubled.)


Duncan Murdoch

__
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] Get an expected value for Order Statistics by applying double integrals

2012-12-11 Thread kyong park
Thomas,

Thanks for enlighting me about using pnorm.The reason I was going to
use the double integral was for  the cumulative distribution fuction F(X)
in the formula. I just tried your method, and  it worked which saved me a
lot of time.

Thanks.

Kyong

On Thu, Dec 6, 2012 at 3:41 PM, Thomas Stewart wrote:

> Kyong-
>
> It isn't clear to me why are you using a double integral.  You have the
> pdf and your goal is to calculate the expected value of a univariate random
> variable (the first order statistic).
>
> Shouldn't the expected value be  E[X_(1)] = int x * 5 * f(x) * (1-F(x))^4
> dx ?  A single integral?
>
> Here are two different numerical techniques to calculate the expected
> value.
>
> -tgs
>
>  fff <- function(x) 5 * x * dnorm(x) * (1 - pnorm(x))^4
> integrate(fff,-Inf,Inf)
>
> M <- 10
> N <- 5
> D <- matrix(rnorm(M*N),nrow=M)
> mean(apply(D,1,min))
>
>
>  On Thu, Dec 6, 2012 at 1:14 PM, kyong park  wrote:
>
>>  Hi  R users,
>>
>>
>>
>>  I’d like to get an expected value for  a minimum value from order
>> statistics of sample size, say, 5 for standard normal distribution, and
>> the
>> formula would be 5* Integral (from -inf  to Inf) x*f(x)* (1-F(x))^4,where
>> f(x) and F(x) are a standard normal density  and a cumulative distribution
>> function respectively. After searching R posts, I applied the following
>> double integral formula which gave an error message saying “the integral
>> is
>> probably divergent.”
>>
>>
>>
>>  integrate(function(y){
>>
>>
>>
>> + sapply(y,function(y){
>>
>>
>>
>> +
>>
>> integrate(function(x)5*y*(1/sqrt(2*pi))*exp(-y^2/2)*(1-(1/sqrt(2*pi))*exp(-x^2/2))^4,-Inf,y)$value})
>>
>>
>>
>> + },-Inf,Inf)
>>
>>
>>
>> I’m  not sure whether the syntax  is correct or not. Appreciate your help.
>>
>>
>>
>> Kyong
>>
>> [[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.
>>
>>
>

[[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] How do you use agrep inside a loop

2012-12-11 Thread Rui Barradas

Hello,

Inline.
Em 11-12-2012 12:04, surekha nagabhushan escreveu:

Rui,

I have initialized it...doesn't seem to help...

result_vector <- vector()


No! This must be just before the loop in 'j'


result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
   for(j in (i+1):length(test1))
   {
   result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
= TRUE, max.distance = 0.1)
   }
   result[[i]]<- result_vector
}

whenever agrep does not find a match it returns character(0), length zero,
do you suppose it has anything to do with that?


Yes, without testing for length zero it throws an error, "replacement 
has length zero".


Hope this helps,

Rui Barradas


Thank you.

On Tue, Dec 11, 2012 at 5:13 PM, Rui Barradas  wrote:


Hello,

See if this is it. You must reinitialize 'result_vector' just before the
loop that constructs it.


test1 <- c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new Mumbai",

 "Thana", "Surekha", "Thane(w)", "surekhaN")

result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1)){
 result_vector <- vector()
 for(j in (i+1):length(test1)){
 tmp <- agrep(test1[i], test1[j],

 ignore.case = TRUE, value = TRUE,
 max.distance = 0.1)
 if(length(tmp) > 0) result_vector[j-i] <- tmp
 }
 result[[i]] <- result_vector
}
result



Hope this helps,

Rui Barradas
Em 11-12-2012 11:23, surekha nagabhushan escreveu:


Pascal,

result_vector <- vector()
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
for(j in (i+1):length(test1))
{
result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE,
value
= TRUE, max.distance = 0.1)
}
result[[i]]<- result_vector
}

I'm not sure what the problem is with the dimension/length of result which
is a list. But I just use the second line: result <- vector("list",
(length(test1)-1))

What am I missing?

Thank you Rui Barradas.

On Tue, Dec 11, 2012 at 4:25 PM, Rui Barradas 
wrote:

  Hello,

And another error in line 2. It should be

for(j in (i+1):length(test1))


Hope this helps,

Rui Barradas

Em 11-12-2012 07:54, Pascal Oettli escreveu:

   Hi,


There is a mistake in the first line. It should be:


for(i in 1:(length(test1)-1))


Regards,
Pascal


Le 11/12/2012 16:01, surekha nagabhushan a écrit :

  Hi all.

This is my first message at R-help...so I'm hoping I have some
beginner's
luck and get some good help for my problem!

FYI I have just started using R recently so my knowledge of R is pretty
preliminary.

Okay here is what I need help with - I need to know how to use agrep
in a
for loop.

I need to compare elements of a vector of names with other elements of
the
same vector.

However if I use something like this:

for(i in 1:length(test1)-1)
{
 for(j in i+1:length(test1))
 {
 result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE,
value
=
TRUE, max.distance = 0.1)
 }

}

I get an error message saying - invalid 'pattern' argument. -* Error in
agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE,
max.distance
=
0.1) : *
*  invalid 'pattern' argument*

Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new
Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")

This is the first time I'm using agrep, I do not understand how it
works
fully...

Kindly help...

Thank you.

Su.

  [[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-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-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] Dispatching on a dgCMatrix does not work.

2012-12-11 Thread Søren Højsgaard
I represent a graph as an adjacency matrix of class "dgCMatrix" (from the 
Matrix package).

> xx
5 x 5 sparse Matrix of class "dgCMatrix"
  a b c d e
a . 1 1 . .
b 1 . 1 . .
c 1 1 . 1 1
d . . 1 . 1
e . . 1 1 .

To check if the matrix defines and undirected graph, I have made the following 
functions/methods:

is.UG <- function (object) {
   UseMethod("is.UG")  
}
is.UG.dgCMatrix <- function (object) {
is.adjMAT(object) && (max(abs(t(object) - object)) == 0)
}

Note: 1) is.adjMAT is homegrown and 2) I know there is an "isSymmetric" method, 
but I can't get that to work either. These functions are in a package and when 
I load the package I get:

> is.UG(xx)
Error in t.default(object) : argument is not a matrix

> is.UG.dgCMatrix(xx)
Error in t.default(object) : argument is not a matrix

Interestingly, if I copy and past the definitions above into an R-session 
things do work:

> is.UG <- function (object) {
+UseMethod("is.UG")  
+ }
> is.UG.dgCMatrix <- function (object) {
+ is.adjMAT(object) && (max(abs(t(object) - object)) == 0)
+ }
> 
> is.UG(xx)
[1] TRUE
> is.UG.dgCMatrix(xx)
[1] TRUE

Can anyone help here?

Best regards
Søren


xx <- new("dgCMatrix"
, i = c(1L, 2L, 0L, 2L, 0L, 1L, 3L, 4L, 2L, 4L, 2L, 3L)
, p = c(0L, 2L, 4L, 8L, 10L, 12L)
, Dim = c(5L, 5L)
, Dimnames = list(c("a", "b", "c", "d", "e"), c("a", "b", "c", "d", "e"))
, x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
, factors = list()

__
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] Renaming column names according to another dataframe

2012-12-11 Thread Johannes Radinger
Hi,

thank you so much, that works perfectly. I used
the first suggestion by Anthony (names( df ) <- df_names[ match(
names( df ) , df_names[ , 'code' ] ) , 'name' ]).
Thank you for the hint about ?match... that was the function I was
looking for, makes comparing vectors very easy.

best,
/Johannes

On Tue, Dec 11, 2012 at 1:06 PM, arun  wrote:
> HI,
>
> You can also try this:
> df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
> df_names <- data.frame(code=c("A","B","D","E","C"),name=c("Col A","Col 
> B","Col D","Col E","Col C"))
>
> names(df)<-df_names$name[match(names(df),df_names$code)]
>
>
> A.K.
>
> - Original Message -
> From: Johannes Radinger 
> To: r-help@r-project.org
> Cc:
> Sent: Tuesday, December 11, 2012 5:55 AM
> Subject: [R] Renaming column names according to another dataframe
>
> Hi,
>
> I've got a dataframe having a code as column name.
> Addtionally I have another dataframe with a two columns (and lots of
> rows), the first
> containing the code and the second some Text (real name).
>
> Now I'd like to use the information (pairs of code and name) of the
> second dataframe to rename all the columnnames in the first dataframe.
> How is it possible to achieve that?
>
> Here a small example of the two dataframes:
>
> df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
> df_names <- data.frame(code=c("A","B","C","D","E"),name=c("Col A","Col
> B","Col C","Col D","Col E"))
>
> /j
>
> __
> 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-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] Writing escaped unicode

2012-12-11 Thread David Kulp
Thanks, Jan.  Unfortunately I have huge streams of data to transmit and it 
should be mostly human readable, too, so escape encoding the entire string 
isn't an option.
A workaround is that I found I can use the rjson package as in

> cat(toJSON(fromJSON("\"Unicode char: \ufffd\"")))
"Unicode char: \ufffd"

but this seems like an awful hack and suggests that there really is a better 
way to escape extended characters.


> From: Jan T Kim 
> Subject: Re: [R] Writing escaped unicode
> Date: December 11, 2012 5:49:18 AM EST
> To: r-help@r-project.org
> 
> 
> On Mon, Dec 10, 2012 at 11:46:40PM -0500, David Kulp wrote:
>> I'd like to write unicode strings using the "\u" escape syntax.  According 
>> to the documentation, print.default or encodeString will escape unicode 
>> using the \u convention.  In practice, I can't make it work.
>> 
>>> b="Unicode character: \ufffd"
>>> print.default(b)
>> [1] "Unicode character: ???"
>>> encodeString(b)
>> [1] "Unicode character: ???"
>> 
>> I want to write the string back out in the same escape formatting as I read 
>> it in.  This is because I'm interfacing with some Ruby code that requires 
>> unicode to be in this escaped format.
> 
> as I read the documentation, encodeString escapes control characters,
> but not "unicode characters". The notion of a "unicode character" is
> not entirely well defined, considering that the very mission of the
> unicode consortium is to make sure that there are no non-unicode
> characters...  ;-)
> 
>> From this it follows that replacing all characters with their \u
> representation, e.g. by
> 
>paste(sprintf("\\u%04x", utf8ToInt(b)), collapse = "");
> 
> should work with the Ruby client you try to talk to. Obviously, this
> bloats the string rather more than necessary (particularly if most of
> the characters are in the ASCII range), but if the volume you're
> piping into the client is small, this may be good enough.
> 
> Best regards, Jan
> -- 
> +- Jan T. Kim ---+
> | email: jtt...@gmail.com|
> | WWW:   http://www.jtkim.dreamhosters.com/  |
> *-=<  hierarchical systems are for files, not for humans  >=-*
> 


[[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] about difMH, loop, and output

2012-12-11 Thread Yung Chih Ou
Dear all:

I have 10 response matrices with missing data.

I used difMH to detect DIF items.

syntax as:
n<-10
difMH<-list()
for (i in 1:10){
  difMH[[i]]<-difMH(respM[[i]], group="group", focal.name=1 , MHstat="MHChisq",
correct=TRUE, exact=FALSE, alpha=0.05, purify=FALSE,
nrIter=10, save.output=TRUE)

but the output only contains the last detection result.

maybe I should output the list "difMH"?

I tried:
> lapply(difMH, write, "difMH.txt", append=TRUE)

but, R reveals:
Error in cat(list(...), file, sep, fill, labels, append) :
  argument 1 (type 'list') cannot be handled by 'cat'

please help me.
thanks!

__
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] Removing duplicated values

2012-12-11 Thread Neotropical bat risk assessments

Hi all,

I have been away from R for far too many months and have two questions.
One is likely simple, but not found under help or in many of the 
available R ref., books.


1.  How does one save the results of an analysis from the main console 
to a file without the need to copy and paste?


2. What tools (possibly Plyr or reshape) can be used to remove 
duplicated entries in a data matrix?
I have some 650,000 records in a table (text values for most fields) 
that were imported form a number of sources and now I find that table is 
inflated by anywhere from 2-20 duplicated entries.  I need to remove all 
dupes and only retain unique values.  Excel is choking on this so I 
thought R would be a better and more efficient option.



Tnx,

Bruce

__
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] Removing duplicated values

2012-12-11 Thread Ista Zahn
Hi,

On Tue, Dec 11, 2012 at 9:23 AM, Neotropical bat risk assessments
 wrote:
> Hi all,
>
> I have been away from R for far too many months and have two questions.
> One is likely simple, but not found under help or in many of the available R
> ref., books.
>
> 1.  How does one save the results of an analysis from the main console to a
> file without the need to copy and paste?

Depends on what you are saving and what format you want to save it to. See

?sink
?write.table
?cat

and the data import/export manual

>
> 2. What tools (possibly Plyr or reshape) can be used to remove duplicated
> entries in a data matrix?
> I have some 650,000 records in a table (text values for most fields) that
> were imported form a number of sources and now I find that table is inflated
> by anywhere from 2-20 duplicated entries.

mat <- mat[!duplicated(mat)]

where 'mat' is the name of your matrix

Best,
Ista

 I need to remove all dupes and
> only retain unique values.  Excel is choking on this so I thought R would be
> a better and more efficient option.
>
>
> Tnx,
>
> Bruce
>
> __
> 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-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] converting manual command to loop command

2012-12-11 Thread eliza botto

Dear useRs,
i have certain commands for some operations in R. They are good if you have a 
small dataset but my dataset, apart from what i used in the recent past, is 
prety large. I want to convert these massive sets of commands into a simple 
loop. 
Your help is required on it
thanks in advance
eliza
kindly note:
"e" is matrix whose each column has to be executed into a distance vector

##To get a distance matrix
 
>a<-dist(e[,1], upper=TRUE, diag=TRUE)
 
##To convert it in a matrix
 
>a<-matrix(a, ncol=1)
 
>b<-dist(e[,2], upper=TRUE, diag=TRUE)
 
>b<-matrix(b, ncol=1)
 
>c<-dist(e[,3], upper=TRUE, diag=TRUE)
 
>c<-matrix(c, ncol=1)
 
>d<-dist(e[,4], upper=TRUE, diag=TRUE)
 
>d<-matrix(d, ncol=1)
 
>ee<-dist(e[,5], upper=TRUE, diag=TRUE)
 
>ee<-matrix(ee, ncol=1)
 
>f<-dist(e[, 6], upper=TRUE, diag=TRUE)
 
>f<-matrix(f, ncol=1)
 
>g<-dist(e[, 7], upper=TRUE, diag=TRUE)
 
>g<-matrix(g, ncol=1)
 
>h<-dist(e[, 8], upper=TRUE, diag=TRUE)
 
>h<-matrix(h, ncol=1)

  
[[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] converting manual command to loop command

2012-12-11 Thread Sarah Goslee
Does this solve your problem:

fakedata <- matrix(runif(100), ncol=10)
fakedata.dist <- apply(fakedata, 2, function(x)as.vector(dist(x,
upper=TRUE, diag=TRUE)))


The columns of the resulting matrix contain the distance vectors.

Sarah

On Tue, Dec 11, 2012 at 9:45 AM, eliza botto  wrote:
>
> Dear useRs,
> i have certain commands for some operations in R. They are good if you have a 
> small dataset but my dataset, apart from what i used in the recent past, is 
> prety large. I want to convert these massive sets of commands into a simple 
> loop.
> Your help is required on it
> thanks in advance
> eliza
> kindly note:
> "e" is matrix whose each column has to be executed into a distance vector
>
> ##To get a distance matrix
>
>>a<-dist(e[,1], upper=TRUE, diag=TRUE)
>
> ##To convert it in a matrix
>
>>a<-matrix(a, ncol=1)
>
>>b<-dist(e[,2], upper=TRUE, diag=TRUE)
>
>>b<-matrix(b, ncol=1)
>
>>c<-dist(e[,3], upper=TRUE, diag=TRUE)
>
>>c<-matrix(c, ncol=1)
>
>>d<-dist(e[,4], upper=TRUE, diag=TRUE)
>
>>d<-matrix(d, ncol=1)
>
>>ee<-dist(e[,5], upper=TRUE, diag=TRUE)
>
>>ee<-matrix(ee, ncol=1)
>
>>f<-dist(e[, 6], upper=TRUE, diag=TRUE)
>
>>f<-matrix(f, ncol=1)
>
>>g<-dist(e[, 7], upper=TRUE, diag=TRUE)
>
>>g<-matrix(g, ncol=1)
>
>>h<-dist(e[, 8], upper=TRUE, diag=TRUE)
>
>>h<-matrix(h, ncol=1)
>
>
--
Sarah Goslee
http://www.functionaldiversity.org

__
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] R users in Sarasota FL

2012-12-11 Thread John Nash

In January I will be visiting Sarasota. The directory of user groups
http://blog.revolutionanalytics.com/local-r-groups.html
doesn't show any groups in Florida. Contact me off-list if interested in 
an informal get-together. It might help start another RUG.


JN

__
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] converting manual command to loop command

2012-12-11 Thread eliza botto

Dear Sarah,
thankyou very much it worked...
what if i want traditional distance matrices instead of distance column 
vectors??
i hope i'm not bothering you...
thanks in advance
eliza
 
 

> Date: Tue, 11 Dec 2012 09:57:37 -0500
> Subject: Re: [R] converting manual command to loop command
> From: sarah.gos...@gmail.com
> To: eliza_bo...@hotmail.com
> CC: r-help@r-project.org
> 
> Does this solve your problem:
> 
> fakedata <- matrix(runif(100), ncol=10)
> fakedata.dist <- apply(fakedata, 2, function(x)as.vector(dist(x,
> upper=TRUE, diag=TRUE)))
> 
> 
> The columns of the resulting matrix contain the distance vectors.
> 
> Sarah
> 
> On Tue, Dec 11, 2012 at 9:45 AM, eliza botto  wrote:
> >
> > Dear useRs,
> > i have certain commands for some operations in R. They are good if you have 
> > a small dataset but my dataset, apart from what i used in the recent past, 
> > is prety large. I want to convert these massive sets of commands into a 
> > simple loop.
> > Your help is required on it
> > thanks in advance
> > eliza
> > kindly note:
> > "e" is matrix whose each column has to be executed into a distance vector
> >
> > ##To get a distance matrix
> >
> >>a<-dist(e[,1], upper=TRUE, diag=TRUE)
> >
> > ##To convert it in a matrix
> >
> >>a<-matrix(a, ncol=1)
> >
> >>b<-dist(e[,2], upper=TRUE, diag=TRUE)
> >
> >>b<-matrix(b, ncol=1)
> >
> >>c<-dist(e[,3], upper=TRUE, diag=TRUE)
> >
> >>c<-matrix(c, ncol=1)
> >
> >>d<-dist(e[,4], upper=TRUE, diag=TRUE)
> >
> >>d<-matrix(d, ncol=1)
> >
> >>ee<-dist(e[,5], upper=TRUE, diag=TRUE)
> >
> >>ee<-matrix(ee, ncol=1)
> >
> >>f<-dist(e[, 6], upper=TRUE, diag=TRUE)
> >
> >>f<-matrix(f, ncol=1)
> >
> >>g<-dist(e[, 7], upper=TRUE, diag=TRUE)
> >
> >>g<-matrix(g, ncol=1)
> >
> >>h<-dist(e[, 8], upper=TRUE, diag=TRUE)
> >
> >>h<-matrix(h, ncol=1)
> >
> >
> --
> Sarah Goslee
> http://www.functionaldiversity.org
  
[[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] converting manual command to loop command

2012-12-11 Thread Sarah Goslee
Given the same artificial data I provided, this will store all the
dist objects in a list:
fakedata.dlist <- lapply(1:ncol(fakedata),
function(x)dist(fakedata[,x], upper=TRUE, diag=TRUE))

Sarah


On Tue, Dec 11, 2012 at 10:15 AM, eliza botto  wrote:
> Dear Sarah,
> thankyou very much it worked...
> what if i want traditional distance matrices instead of distance column
> vectors??
> i hope i'm not bothering you...
> thanks in advance
> eliza
>
>
>> Date: Tue, 11 Dec 2012 09:57:37 -0500
>> Subject: Re: [R] converting manual command to loop command
>> From: sarah.gos...@gmail.com
>> To: eliza_bo...@hotmail.com
>> CC: r-help@r-project.org
>>
>> Does this solve your problem:
>>
>> fakedata <- matrix(runif(100), ncol=10)
>> fakedata.dist <- apply(fakedata, 2, function(x)as.vector(dist(x,
>> upper=TRUE, diag=TRUE)))
>>
>>
>> The columns of the resulting matrix contain the distance vectors.
>>
>> Sarah
>>
>> On Tue, Dec 11, 2012 at 9:45 AM, eliza botto 
>> wrote:
>> >
>> > Dear useRs,
>> > i have certain commands for some operations in R. They are good if you
>> > have a small dataset but my dataset, apart from what i used in the recent
>> > past, is prety large. I want to convert these massive sets of commands into
>> > a simple loop.
>> > Your help is required on it
>> > thanks in advance
>> > eliza
>> > kindly note:
>> > "e" is matrix whose each column has to be executed into a distance
>> > vector
>> >
>> > ##To get a distance matrix
>> >
>> >>a<-dist(e[,1], upper=TRUE, diag=TRUE)
>> >
>> > ##To convert it in a matrix
>> >
>> >>a<-matrix(a, ncol=1)
>> >
>> >>b<-dist(e[,2], upper=TRUE, diag=TRUE)
>> >
>> >>b<-matrix(b, ncol=1)
>> >
>> >>c<-dist(e[,3], upper=TRUE, diag=TRUE)
>> >
>> >>c<-matrix(c, ncol=1)
>> >
>> >>d<-dist(e[,4], upper=TRUE, diag=TRUE)
>> >
>> >>d<-matrix(d, ncol=1)
>> >
>> >>ee<-dist(e[,5], upper=TRUE, diag=TRUE)
>> >
>> >>ee<-matrix(ee, ncol=1)
>> >
>> >>f<-dist(e[, 6], upper=TRUE, diag=TRUE)
>> >
>> >>f<-matrix(f, ncol=1)
>> >
>> >>g<-dist(e[, 7], upper=TRUE, diag=TRUE)
>> >
>> >>g<-matrix(g, ncol=1)
>> >
>> >>h<-dist(e[, 8], upper=TRUE, diag=TRUE)
>> >
>> >>h<-matrix(h, ncol=1)
>> >
>> >
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org

__
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] Latitudinal mean of values in a data frame

2012-12-11 Thread Rui Barradas

Hello,

Try the following.

tapply(Value, floor(Lat), FUN = mean)
   6970
0.1805381 0.1617072


Hope this helps,

Rui Barradas
Em 11-12-2012 11:17, Swagath Navin escreveu:

Dear all,

I have a big file containing latitude points(-10 to 80) and 
corresponding values.

Example data

Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 
69.53746, 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 
70.00106, 70.00295, 70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 
70.01049, 70.01053, 70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 
70.01646, 70.01983, 70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 
70.02856, 70.0291, 70.02983, 70.03091, 70.03267, 70.03423)


Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 
0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 
0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 
0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 
0.14388486, 0.19098477, 0.17252013, 0.12965086, 0.12256515, 
0.18159349, 0.15608113, 0.18742996, 0.13858418, 0.16865459, 
0.19058037, 0.12531143, 0.19189732, 0.12019097, 0.1790819, 0.15086053, 
0.18607724,  0.13330366)


dframe=data.frame(Lat, Value)

i would like to find latitudinal mean such that my output looks like 
the below:


Lat Value
69 0.18
70 0.16

I am thankful for any ideas how to perform this or which function i 
should look into.


Thanks a lot for your time,
Cheers,
Navin

__
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-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] Dispatching on a dgCMatrix does not work.

2012-12-11 Thread Martin Morgan

On 12/11/2012 01:46 PM, Søren Højsgaard wrote:

I represent a graph as an adjacency matrix of class "dgCMatrix" (from the 
Matrix package).


xx

5 x 5 sparse Matrix of class "dgCMatrix"
   a b c d e
a . 1 1 . .
b 1 . 1 . .
c 1 1 . 1 1
d . . 1 . 1
e . . 1 1 .

To check if the matrix defines and undirected graph, I have made the following 
functions/methods:

is.UG <- function (object) {
UseMethod("is.UG")
}
is.UG.dgCMatrix <- function (object) {
 is.adjMAT(object) && (max(abs(t(object) - object)) == 0)
}

Note: 1) is.adjMAT is homegrown and 2) I know there is an "isSymmetric" method, 
but I can't get that to work either. These functions are in a package and when I load the 
package I get:


is.UG(xx)

Error in t.default(object) : argument is not a matrix


You take the transpose of a dgCMatrix. This is supposed to use one of the 
showMethods('t') from Matrix, but I guess your package NAMESPACE file does not 
importMethodsFrom(Matrix, t) or similar.


Martin Morgan




is.UG.dgCMatrix(xx)

Error in t.default(object) : argument is not a matrix

Interestingly, if I copy and past the definitions above into an R-session 
things do work:


is.UG <- function (object) {

+UseMethod("is.UG")
+ }

is.UG.dgCMatrix <- function (object) {

+ is.adjMAT(object) && (max(abs(t(object) - object)) == 0)
+ }


is.UG(xx)

[1] TRUE

is.UG.dgCMatrix(xx)

[1] TRUE

Can anyone help here?

Best regards
Søren


xx <- new("dgCMatrix"
 , i = c(1L, 2L, 0L, 2L, 0L, 1L, 3L, 4L, 2L, 4L, 2L, 3L)
 , p = c(0L, 2L, 4L, 8L, 10L, 12L)
 , Dim = c(5L, 5L)
 , Dimnames = list(c("a", "b", "c", "d", "e"), c("a", "b", "c", "d", "e"))
 , x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
 , factors = list()

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




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
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] Latitudinal mean of values in a data frame

2012-12-11 Thread Rui Barradas

Hello, again.

Another possibility is

aggregate(Value, by = list(floor(Lat)), FUN = mean)

Rui Barradas
Em 11-12-2012 11:17, Swagath Navin escreveu:

Dear all,

I have a big file containing latitude points(-10 to 80) and 
corresponding values.

Example data

Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 
69.53746, 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 
70.00106, 70.00295, 70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 
70.01049, 70.01053, 70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 
70.01646, 70.01983, 70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 
70.02856, 70.0291, 70.02983, 70.03091, 70.03267, 70.03423)


Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 
0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 
0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 
0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 
0.14388486, 0.19098477, 0.17252013, 0.12965086, 0.12256515, 
0.18159349, 0.15608113, 0.18742996, 0.13858418, 0.16865459, 
0.19058037, 0.12531143, 0.19189732, 0.12019097, 0.1790819, 0.15086053, 
0.18607724,  0.13330366)


dframe=data.frame(Lat, Value)

i would like to find latitudinal mean such that my output looks like 
the below:


Lat Value
69 0.18
70 0.16

I am thankful for any ideas how to perform this or which function i 
should look into.


Thanks a lot for your time,
Cheers,
Navin

__
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-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] questions on French characters in plot

2012-12-11 Thread Richard Zijdeman
Dear Milan,

thank you for kind suggestion. Converting the characters using:
> iconv(department, "ISO-8859-15", "UTF-8")
indeed improves the situation in that now all values (names of departments) are 
displayed in the plot, although the specific special characters are 
unfortunately appearing as empty boxes.

I have tried to see whether I could 'save' my state file using UTF-8 format, 
and although this proves to be a popular request it does not seem to have been 
incorporated in Stata.

Best and thank you for your help,

Richard


On 11 Dec 2012, at 12:11, Milan Bouchet-Valat  wrote:

> Le mardi 11 décembre 2012 à 01:10 +0100, Richard Zijdeman a écrit :
>> Dear all,
>> 
>> I have imported a dataset from Stata using the foreign package. The
>> original data contain French characters such as  and  .
>> After importing, string variables containing names of French
>> departments have changed. E.g. Ardche became Ard\x8fche. I would like
>> to ask how I could plot these changed strings, since now the strings
>> with special characters fail to be printed in the plot (either using
>> plot() or ggplot2()).
>> 
>> I have googled for solutions, but actually find it hard to determine
>> whether I should change my R setup or should read in the data in a
>> different way. Since I work on a mac I changed my local according to
>> the R for Mac OS X FAQ, chapter 9.  Below is some info on my setup and
>> code and output on what works for me and what does not. Thank you in
>> advance for you comments.
> Accentuated characters should work fine on a machine using a UTF-8
> locale as yours. I think the problem is that the imported data uses
> ISO8859-15 or UTF-16, not UTF-8.
> 
> I have no idea whether .dta files specify an encoding or not, but I
> think you can convert them in R by calling
> iconv(department, "ISO-8859-15", "UTF-8")
> or
> iconv(department, "UTF-16", "UTF-8")
> 
>> Best,
>> 
>> Richard
>> 
>> #--
>> rm(list=ls())
>> sessionInfo()
>> # R version 2.15.2 (2012-10-26)
>> # Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>> #
>> # locale:
>> # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>> 
>> # creating variables
>> department  <- c("Nord","Paris","Ard\x8fche")
> \x8 does not correspond to "è" AFAIK. In ISO8859-1 and -15 and UTF-16,
> it's \xE8 ("\uE8" in R).
> 
> In UTF-8, it's C3 A8, "\303\250" in R.
> 
>> department2 <- c("Nord", "Paris", "Ardche")
>> n   <- c(2,4,1)
>> 
>> # creating dataframes
>> df  <- data.frame(department,n)
>> df2 <- data.frame(department2,n)
>> 
>> department
>> # [1] "Nord"   "Paris"  "Ard\x8fche"
>> department2
>> # [1] "Nord""Paris"   "Ardche"
>> 
>> plot(df) # fails to show the text "Ardche"
>> plot(df2) # shows text "Ardche"
>> 
>> # EOF
>>  [[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-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] Renaming column names according to another dataframe

2012-12-11 Thread arun
HI,
Try this:
 names(df)<-df_names$name[df_names$code%in%names(df)]
 head(df,2)
#  Col A Col B Col C
#1 1 1 1
#2 2 2 2
A.K.




- Original Message -
From: Johannes Radinger 
To: r-help@r-project.org
Cc: 
Sent: Tuesday, December 11, 2012 5:55 AM
Subject: [R] Renaming column names according to another dataframe

Hi,

I've got a dataframe having a code as column name.
Addtionally I have another dataframe with a two columns (and lots of
rows), the first
containing the code and the second some Text (real name).

Now I'd like to use the information (pairs of code and name) of the
second dataframe to rename all the columnnames in the first dataframe.
How is it possible to achieve that?

Here a small example of the two dataframes:

df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
df_names <- data.frame(code=c("A","B","C","D","E"),name=c("Col A","Col
B","Col C","Col D","Col E"))

/j

__
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-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] Renaming column names according to another dataframe

2012-12-11 Thread arun
HI,

You can also try this:
df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
df_names <- data.frame(code=c("A","B","D","E","C"),name=c("Col A","Col B","Col 
D","Col E","Col C"))

names(df)<-df_names$name[match(names(df),df_names$code)]


A.K.

- Original Message -
From: Johannes Radinger 
To: r-help@r-project.org
Cc: 
Sent: Tuesday, December 11, 2012 5:55 AM
Subject: [R] Renaming column names according to another dataframe

Hi,

I've got a dataframe having a code as column name.
Addtionally I have another dataframe with a two columns (and lots of
rows), the first
containing the code and the second some Text (real name).

Now I'd like to use the information (pairs of code and name) of the
second dataframe to rename all the columnnames in the first dataframe.
How is it possible to achieve that?

Here a small example of the two dataframes:

df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
df_names <- data.frame(code=c("A","B","C","D","E"),name=c("Col A","Col
B","Col C","Col D","Col E"))

/j

__
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-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] Comparing Kappa coefficients

2012-12-11 Thread moadeep
I have a simple R script which uses the psych package to calculate cohens
kappa (weighted) from a csv file. The csv file has 2 columns of ordinal data
- one ranked by an experienced observer and the other by a novice who is
undergoing training. What I would like to do is measure kappa for subsets of
this data (say 30-50 ratings) and check whether the observed agreement
between novice and experienced observer improves with training. Which metric
should I use to compare to kappas? At the moment the 95% CI for 100
observations is quite wide -  0.31 - 0.71



--
View this message in context: 
http://r.789695.n4.nabble.com/Comparing-Kappa-coefficients-tp4652780.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] Troubles with subset()

2012-12-11 Thread Virgile Capo-Chichi
All,
I have the attached dataset which I read from SPSS and transformed a little
bit using the attached script. I am trying to run a logistic regression
using glm() on a subset of my data. When I run the logistic regression on
the whle dataset, it runs OK. As soon as I try to run on the subset, I get
an error message related to different lengths of variables. Any idea why
this might be so? Thanks for your inputs. V
__
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] query multiple terms in PubMed abstract

2012-12-11 Thread email
Hi:

I am trying to search PubMed abstracts which contains BOTH two terms:
COL4A1 AND Ocular. I am using the following code:

url= "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?";
search = paste(url,
"db=pubmed&term=COL4A1+AND+Ocular[abstract]&retmax=300", sep="")
docId <- xmlTreeParse(getURL(paste(url, search, sep="")),
useInternalNodes=TRUE)


I want to get the reply where BOTH the terms exist in abstract. But it is
not doing that now. Any idea?

Thanks
john

[[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] Variable importance in Party package

2012-12-11 Thread kimpeterson
I'm attempting to use function varimpAUC in the Party package but get a "not
found" message. It was reportedly added September 26th to party_1.0-3, so I
wonder if it was not included in the Windows binary that I downloaded. Can
anyone please tell me how to access this function? Thanks in advance!

Here's the message I get:

> data.cforest.varimp <- varimpAUC(data.cforest, conditional = TRUE)
Error: could not find function "varimpAUC"




--
View this message in context: 
http://r.789695.n4.nabble.com/Variable-importance-in-Party-package-tp4652797.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] VarimpAUC in Party Package

2012-12-11 Thread Peterson, Kim - DNR
Greetings! I'm trying to use function varimpAUC in the party package 
(party_1.0-3 released September 26th of this year). Unfortunately, I get the 
following error message:

> data.cforest.varimp <- varimpAUC(data.cforest, conditional = TRUE)
Error: could not find function "varimpAUC"

Was this function NOT included in the Windows binary I downloaded and 
installed? Could someone please tell me how to access it?

Thanks!

Kim Peterson
Research Scientist
Bureau of Science Services
Wisconsin Department of Natural Resources
(*) phone:  (608) 266-5227
(*) fax:(608) 267-5231
(*) e-mail: kim.peter...@wisconsin.gov
Website: dnr.wi.gov
Find us on Facebook: www.facebook.com/WIDNR





[[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] questions on French characters in plot

2012-12-11 Thread Milan Bouchet-Valat
Le mardi 11 décembre 2012 à 16:41 +0100, Richard Zijdeman a écrit :
> Dear Milan,
> 
> thank you for kind suggestion. Converting the characters using:
> > iconv(department, "ISO-8859-15", "UTF-8")
> indeed improves the situation in that now all values (names of
> departments) are displayed in the plot, although the specific special
> characters are unfortunately appearing as empty boxes.
I wouldn't call that an improvement... :-/

What's the result of the other one, i.e.
iconv(department, "UTF-16", "UTF-8")

> I have tried to see whether I could 'save' my state file using UTF-8
> format, and although this proves to be a popular request it does not
> seem to have been incorporated in Stata.
You should not need this. iconv() should be able to convert the strings
to something usable. The problem is to determine what's the original
encoding. Could you call
lapply(department, charToRaw)

and post the output?


Regards

> Best and thank you for your help,
> 
> Richard
> 
> 
> On 11 Dec 2012, at 12:11, Milan Bouchet-Valat  wrote:
> 
> > Le mardi 11 décembre 2012 à 01:10 +0100, Richard Zijdeman a écrit :
> >> Dear all,
> >> 
> >> I have imported a dataset from Stata using the foreign package. The
> >> original data contain French characters such as  and  .
> >> After importing, string variables containing names of French
> >> departments have changed. E.g. Ardche became Ard\x8fche. I would like
> >> to ask how I could plot these changed strings, since now the strings
> >> with special characters fail to be printed in the plot (either using
> >> plot() or ggplot2()).
> >> 
> >> I have googled for solutions, but actually find it hard to determine
> >> whether I should change my R setup or should read in the data in a
> >> different way. Since I work on a mac I changed my local according to
> >> the R for Mac OS X FAQ, chapter 9.  Below is some info on my setup and
> >> code and output on what works for me and what does not. Thank you in
> >> advance for you comments.
> > Accentuated characters should work fine on a machine using a UTF-8
> > locale as yours. I think the problem is that the imported data uses
> > ISO8859-15 or UTF-16, not UTF-8.
> > 
> > I have no idea whether .dta files specify an encoding or not, but I
> > think you can convert them in R by calling
> > iconv(department, "ISO-8859-15", "UTF-8")
> > or
> > iconv(department, "UTF-16", "UTF-8")
> > 
> >> Best,
> >> 
> >> Richard
> >> 
> >> #--
> >> rm(list=ls())
> >> sessionInfo()
> >> # R version 2.15.2 (2012-10-26)
> >> # Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> >> #
> >> # locale:
> >> # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> >> 
> >> # creating variables
> >> department  <- c("Nord","Paris","Ard\x8fche")
> > \x8 does not correspond to "è" AFAIK. In ISO8859-1 and -15 and UTF-16,
> > it's \xE8 ("\uE8" in R).
> > 
> > In UTF-8, it's C3 A8, "\303\250" in R.
> > 
> >> department2 <- c("Nord", "Paris", "Ardche")
> >> n   <- c(2,4,1)
> >> 
> >> # creating dataframes
> >> df  <- data.frame(department,n)
> >> df2 <- data.frame(department2,n)
> >> 
> >> department
> >> # [1] "Nord"   "Paris"  "Ard\x8fche"
> >> department2
> >> # [1] "Nord""Paris"   "Ardche"
> >> 
> >> plot(df) # fails to show the text "Ardche"
> >> plot(df2) # shows text "Ardche"
> >> 
> >> # EOF
> >>[[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-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] Tools for Building Packages (Fedora)

2012-12-11 Thread Tony Paredes
Hello everyone,

I'm trying to install the tools to build packages under Fedora (17), and
have little luck finding anything useful using Google. I wanted to ask if
there is any documentation associated with this issue; a link will be very
useful.

Thank you very much.

[[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] Troubles with subset()

2012-12-11 Thread Milan Bouchet-Valat
Le mardi 11 décembre 2012 à 15:09 +0100, Virgile Capo-Chichi a écrit :
> All,
> I have the attached dataset which I read from SPSS and transformed a little
> bit using the attached script. I am trying to run a logistic regression
> using glm() on a subset of my data. When I run the logistic regression on
> the whle dataset, it runs OK. As soon as I try to run on the subset, I get
> an error message related to different lengths of variables. Any idea why
> this might be so? Thanks for your inputs. V
Please paste the code, as it was removed by the server.

Most likely, it comes from the fact that some terms in the formula refer
to variables in the 'data' argument, and some do not.


Regards

__
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] Troubles with subset()

2012-12-11 Thread Milan Bouchet-Valat
Le mardi 11 décembre 2012 à 17:18 +0100, Virgile Capo-Chichi a écrit :
> Hello all,
> 
> I have the attached dataset which I read from SPSS and transformed a
> little bit using the script below. I am trying to run a logistic
> regression using glm() on a subset of my data. When I run the logistic
> regression on the whle dataset, it runs OK. As soon as I try to run on
> the subset, I get an error message related to different lengths of
> variables. Any idea why this might be so? Thanks for your inputs. V
This code doesn't work, because the MC0911 object does not exist.

It works fine, though, if I replace all occurrences of MC0911 with
MC0911_S, and CCU2 with ccu2.

The morale of the story is, do not use attach() but pass the data frame
via the 'data' argument to glm(), and when something is weird, close the
R session and start with a clean environment.


Regards

> Here is my code. Not sure if the data itself got itself through.
> ===
> library (foreign)
> library (Hmisc)
> MC0911_S <- read.spss("C:/Users/samsung/Desktop/R
> Pilot/MC0911_S.sav", 
>   use.value.labels=FALSE, max.value.labels=Inf, to.data.frame=TRUE)
> 
> colnames(MC0911) <- tolower(colnames(MC0911))
> 
> MC0911_S <-transform (MC0911_S, age=2009-a1)
> MC0911_S <-transform (MC0911_S, b34=b4/b3) 
> MC0911_S <-transform (MC0911_S, CCU=b34+b7+b8)
> MC0911_S$CCU2 [MC0911_S$CCU==4] <-"1"
> MC0911_S$CCU2 [MC0911_S$CCU!=4] <-"0"
> MC0911_S$a3<-as.factor(MC0911_S$a3)
> MC0911_S$a6<-as.factor(MC0911_S$a6)
> MC0911_S$CCU2<-as.numeric(MC0911_S$CCU2)
> attach(MC0911_S)
> glm(CCU2~age+a3+a6+a8+a9, family=binomial)
> detach()
> MC0911_2<-subset(MC0911, year>2009)
> attach(MC0911_2)
> glm(CCU2~age+a3+a6+a8+a9, family=binomial)
> detach()
> 
> 
> 2012/12/11 Milan Bouchet-Valat 
> Le mardi 11 décembre 2012 à 15:09 +0100, Virgile Capo-Chichi a
> écrit :
> > All,
> > I have the attached dataset which I read from SPSS and
> transformed a little
> > bit using the attached script. I am trying to run a logistic
> regression
> > using glm() on a subset of my data. When I run the logistic
> regression on
> > the whle dataset, it runs OK. As soon as I try to run on the
> subset, I get
> > an error message related to different lengths of variables.
> Any idea why
> > this might be so? Thanks for your inputs. V
> 
> Please paste the code, as it was removed by the server.
> 
> Most likely, it comes from the fact that some terms in the
> formula refer
> to variables in the 'data' argument, and some do not.
> 
> 
> Regards
>

__
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] Fwd: Troubles with subset()

2012-12-11 Thread Virgile Capo-Chichi
Trying again with a smaller data file. V




Hello all,

I have the attached dataset which I read from SPSS and transformed a little
bit using the script below. I am trying to run a logistic regression using
glm() on a subset of my data. When I run the logistic regression on the
whle dataset, it runs OK. As soon as I try to run on the subset, I get an
error message related to different lengths of variables. Any idea why this
might be so? Thanks for your inputs. V


Here is my code. Not sure if the data itself got itself through.
===
library (foreign)
library (Hmisc)
MC0911_S <- read.spss("C:/Users/samsung/Desktop/R Pilot/MC0911_S.sav",
  use.value.labels=FALSE, max.value.labels=Inf, to.data.frame=TRUE)

colnames(MC0911) <- tolower(colnames(MC0911))

MC0911_S <-transform (MC0911_S, age=2009-a1)
MC0911_S <-transform (MC0911_S, b34=b4/b3)
MC0911_S <-transform (MC0911_S, CCU=b34+b7+b8)
MC0911_S$CCU2 [MC0911_S$CCU==4] <-"1"
MC0911_S$CCU2 [MC0911_S$CCU!=4] <-"0"
MC0911_S$a3<-as.factor(MC0911_S$a3)
MC0911_S$a6<-as.factor(MC0911_S$a6)
MC0911_S$CCU2<-as.numeric(MC0911_S$CCU2)
attach(MC0911_S)
glm(CCU2~age+a3+a6+a8+a9, family=binomial)
detach()
MC0911_2<-subset(MC0911, year>2009)
attach(MC0911_2)
glm(CCU2~age+a3+a6+a8+a9, family=binomial)
detach()



2012/12/11 Milan Bouchet-Valat 

> Le mardi 11 décembre 2012 à 15:09 +0100, Virgile Capo-Chichi a écrit :
> > All,
> > I have the attached dataset which I read from SPSS and transformed a
> little
> > bit using the attached script. I am trying to run a logistic regression
> > using glm() on a subset of my data. When I run the logistic regression on
> > the whle dataset, it runs OK. As soon as I try to run on the subset, I
> get
> > an error message related to different lengths of variables. Any idea why
> > this might be so? Thanks for your inputs. V
> Please paste the code, as it was removed by the server.
>
> Most likely, it comes from the fact that some terms in the formula refer
> to variables in the 'data' argument, and some do not.
>
>
> Regards
>
__
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] Tools for Building Packages (Fedora)

2012-12-11 Thread Milan Bouchet-Valat
Le mardi 11 décembre 2012 à 10:59 -0500, Tony Paredes a écrit :
> Hello everyone,
> 
> I'm trying to install the tools to build packages under Fedora (17), and
> have little luck finding anything useful using Google. I wanted to ask if
> there is any documentation associated with this issue; a link will be very
> useful.
What kind of packages do you want to build? R itself, or R packages?

In both cases, I think this may help:
yum groupinstall development-tools


My two cents

__
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] Tools for Building Packages (Fedora)

2012-12-11 Thread Marc Schwartz
On Dec 11, 2012, at 9:59 AM, Tony Paredes  wrote:

> Hello everyone,
> 
> I'm trying to install the tools to build packages under Fedora (17), and
> have little luck finding anything useful using Google. I wanted to ask if
> there is any documentation associated with this issue; a link will be very
> useful.
> 
> Thank you very much.



As an FYI, there is a dedicated R-SIG list for Fedora that you should subscribe 
and post to instead of here relative to Fedora specific issues. More 
information is available at:

  https://stat.ethz.ch/mailman/listinfo/r-sig-fedora

For quick references, presuming that you are not looking to build RPMs and 
primarily build 'source' packages for R, such as would be available on CRAN, 
you should start by reviewing The R Installation and Administration Manual:

  http://cran.r-project.org/doc/manuals/r-release/R-admin.html

perhaps specifically Appendix A, especially if you might be including 
C/C++/FORTRAN code in your package, and the Writing R Extensions Manual:

  http://cran.r-project.org/doc/manuals/r-release/R-exts.html

Both contain relevant information regarding various tools that you may need and 
that may not be a part of a typical Fedora install these days.

If you get to the point where you have R package development questions that are 
not really Fedora specific, those should be posted to the R-Devel list:

  https://stat.ethz.ch/mailman/listinfo/r-devel

Regards,

Marc Schwartz

__
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] Removing named objects using rm(..)

2012-12-11 Thread William Dunlap
By 'testing for existence in a given environment' I meant to use
exists(dataName, env=theEnvironment, inherits=FALSE)
E.g.,
   > rm(t)
   > exists("t", envir=globalenv())
   [1] TRUE
   > exists("t", envir=globalenv(), inherits=FALSE)
   [1] FALSE
Look at help("exists") for details.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

From: Worik R [mailto:wor...@gmail.com]
Sent: Monday, December 10, 2012 9:42 PM
To: William Dunlap
Cc: r-help
Subject: Re: [R] Removing named objects using rm(..)



You may find it more reliable to define an environment in which you
will be storing your data (perhaps globalenv(), perhaps something created
by new.env())  and then testing for existence of a dataset by a given name
in that environment.

I did that.

PAIR.ENV <- new.env()

get("USDCHF", env=PAIR.ENV)

returns trhe USDCHF defined in timeSeries

This is very hard!

Worik
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 Worik R
> Sent: Monday, December 10, 2012 5:47 PM
> To: Duncan Murdoch
> Cc: r-help
> Subject: Re: [R] Removing named objects using rm(..)
>
> On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch
> mailto:murdoch.dun...@gmail.com>>wrote:
>
> > On 12-12-10 7:33 PM, Worik R wrote:
> >
> >> Let me restate my question.
> >>
> >> Is there a straightforward way of ensuring I can use the variable name
> >> USDCHF?
> >>
> >
> > You can use any legal variable name.  The only risk is that you will
> > overwrite some other variable that you created.  You can't overwrite
> > variables from packages.  (You might mask them, but they are still
> > accessible using the :: notation.  E.g. after you set
> >
> > USDCHF <- NULL
> >
>
> Exactly.  I got around this by assigning NULL to the variable names that I
> would have deleted.  Then instead of testing for existence I tested for
> NULL.
>
>
> >
> > you can still access the one in timeSeries using
> >
> > timeSeries::USDCHF
>
>
> Christ.  That is what I wanted to delete.  I read the scoping section of
> R-Lang (again) and nothing  I could see prepared me for the shock of...
>
> > library(timeSeries)
> > nrow(USDCHF)
> [1] 62496
> > rm(USDCHF)
> Warning message:
> In rm(USDCHF) : object 'USDCHF' not found
> > nrow(USDCHF)
> [1] 62496
>
>
> The message from rm was that USDCHF did not exist.  But I can still access
> its properties with nrow.
>
> This is very broken.  I would not have believed I would see that in the
> 21st century with a modern language.  (Oh wait, there is Javascript and
> PHP, so in comparison R is not that broken)
>
> I am not new to R, I have been (mis)using it for 5 years.  I love aspects
> of R, but this and a few other things (lack of debugging support and
> ignoring the "principle of least surprise" are two biggies) are very
> frustrating.  Without debugging support or more help from the compiler
> (like a "cannot rm EURCHF" message instead of a lie) R causes as many
> problems as it solves.
>
> Sigh.  Thanks for the help.
>
> Worik
>
>
>
>
> >
>
>   [[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.


[[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] eigenvector centrality

2012-12-11 Thread Bita Shams
Hello, 


I need to calculate all eigenvectors of network adjacency matrix.

to do this, I called evcent function such as following

p2=evcent(g, options=list(nev=2)) where g is my graph and nev is number of 
required eigenvector

but it only calculated first eigenvector and p2$options$nev was still one 
instead of two.

I will appreciate if anybody could help me to solve my problem.

Many thanks,

B.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] Troubles with subset()

2012-12-11 Thread Virgile Capo-Chichi
Hello all,

I have the attached dataset which I read from SPSS and transformed a little
bit using the script below. I am trying to run a logistic regression using
glm() on a subset of my data. When I run the logistic regression on the
whle dataset, it runs OK. As soon as I try to run on the subset, I get an
error message related to different lengths of variables. Any idea why this
might be so? Thanks for your inputs. V


Here is my code. Not sure if the data itself got itself through.
===
library (foreign)
library (Hmisc)
MC0911_S <- read.spss("C:/Users/samsung/Desktop/R Pilot/MC0911_S.sav",
  use.value.labels=FALSE, max.value.labels=Inf, to.data.frame=TRUE)

colnames(MC0911) <- tolower(colnames(MC0911))

MC0911_S <-transform (MC0911_S, age=2009-a1)
MC0911_S <-transform (MC0911_S, b34=b4/b3)
MC0911_S <-transform (MC0911_S, CCU=b34+b7+b8)
MC0911_S$CCU2 [MC0911_S$CCU==4] <-"1"
MC0911_S$CCU2 [MC0911_S$CCU!=4] <-"0"
MC0911_S$a3<-as.factor(MC0911_S$a3)
MC0911_S$a6<-as.factor(MC0911_S$a6)
MC0911_S$CCU2<-as.numeric(MC0911_S$CCU2)
attach(MC0911_S)
glm(CCU2~age+a3+a6+a8+a9, family=binomial)
detach()
MC0911_2<-subset(MC0911, year>2009)
attach(MC0911_2)
glm(CCU2~age+a3+a6+a8+a9, family=binomial)
detach()


2012/12/11 Milan Bouchet-Valat 

> Le mardi 11 décembre 2012 à 15:09 +0100, Virgile Capo-Chichi a écrit :
> > All,
> > I have the attached dataset which I read from SPSS and transformed a
> little
> > bit using the attached script. I am trying to run a logistic regression
> > using glm() on a subset of my data. When I run the logistic regression on
> > the whle dataset, it runs OK. As soon as I try to run on the subset, I
> get
> > an error message related to different lengths of variables. Any idea why
> > this might be so? Thanks for your inputs. V
> Please paste the code, as it was removed by the server.
>
> Most likely, it comes from the fact that some terms in the formula refer
> to variables in the 'data' argument, and some do not.
>
>
> Regards
>
__
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] Latitudinal mean of values in a data frame

2012-12-11 Thread arun
Hi,
In addition, you can also use:
?trunc(), ?substr() etc.

 aggregate(Value, by = list(floor(Lat)), FUN = function(x) signif(mean(x),2))
#  Group.1    x
#1  69 0.18
#2  70 0.16


  aggregate(Value, by = list(substr(Lat,1,2)), FUN = function(x) 
signif(mean(x),2))
#  Group.1    x
#1  69 0.18
#2  70 0.16

 aggregate(Value, by = list(trunc(Lat)), FUN = function(x) signif(mean(x),2)) 
 Group.1    x
#1  69 0.18
#2  70 0.16
A.K.


- Original Message -
From: Rui Barradas 
To: Swagath Navin 
Cc: r-help@r-project.org
Sent: Tuesday, December 11, 2012 10:27 AM
Subject: Re: [R] Latitudinal mean of values in a data frame

Hello, again.

Another possibility is

aggregate(Value, by = list(floor(Lat)), FUN = mean)

Rui Barradas
Em 11-12-2012 11:17, Swagath Navin escreveu:
> Dear all,
> 
> I have a big file containing latitude points(-10 to 80) and corresponding 
> values.
> Example data
> 
> Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 69.53746, 
> 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 70.00106, 70.00295, 
> 70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 70.01049, 70.01053, 
> 70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 70.01646, 70.01983, 
> 70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 70.02856, 70.0291, 70.02983, 
> 70.03091, 70.03267, 70.03423)
> 
> Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 
> 0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 
> 0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 
> 0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 0.14388486, 
> 0.19098477, 0.17252013, 0.12965086, 0.12256515, 0.18159349, 0.15608113, 
> 0.18742996, 0.13858418, 0.16865459, 0.19058037, 0.12531143, 0.19189732, 
> 0.12019097, 0.1790819, 0.15086053, 0.18607724,  0.13330366)
> 
> dframe=data.frame(Lat, Value)
> 
> i would like to find latitudinal mean such that my output looks like the 
> below:
> 
> Lat Value
> 69 0.18
> 70 0.16
> 
> I am thankful for any ideas how to perform this or which function i should 
> look into.
> 
> Thanks a lot for your time,
> Cheers,
> Navin
> 
> __
> 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-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-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] Latitudinal mean of values in a data frame

2012-12-11 Thread David Winsemius


On Dec 11, 2012, at 3:17 AM, Swagath Navin wrote:


Dear all,

I have a big file containing latitude points(-10 to 80) and  
corresponding values.

Example data

Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308,  
69.53746, 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055,  
70.00106, 70.00295, 70.00308, 70.00363, 70.00427, 70.00665,  
70.00906, 70.01049, 70.01053, 70.01075, 70.01208, 70.01236,  
70.01418, 70.01452, 70.01646, 70.01983, 70.0209, 70.02298, 70.02386,  
70.02533, 70.02534, 70.02856, 70.0291, 70.02983, 70.03091, 70.03267,  
70.03423)


Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901,  
0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046,  
0.18542965, 0.13914858, 0.1654665, 0.12885736, 0.18935319,  
0.1912378, 0.14910094, 0.17590007, 0.18369354, 0.12546185,  
0.16096813, 0.18851039, 0.14388486, 0.19098477, 0.17252013,  
0.12965086, 0.12256515, 0.18159349, 0.15608113, 0.18742996,  
0.13858418, 0.16865459, 0.19058037, 0.12531143, 0.19189732,  
0.12019097, 0.1790819, 0.15086053, 0.18607724,  0.13330366)


dframe=data.frame(Lat, Value)

i would like to find latitudinal mean such that my output looks like  
the below:


Lat Value
69 0.18
70 0.16


?trunc   # some people prefer floor()
?tapply

--

David Winsemius, MD
Alameda, CA, USA

__
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] Retain last grouping after a strsplit()

2012-12-11 Thread Steven Ranney
All -

I have a column of SiteNames:

SiteName
OYS-PIA2-FL-1
OYS-PIA2-LA-1
OYS-PI-LA-BB-1
OYS-PIA2-LA-10
...
[truncated]

and I want to include only the last few digits into a new column.

I tried

substr(data$SiteName, 13, 20)

but because some SiteName values are of a different length, the final
hyphen (i.e., "-") was included:

"1"
"1"
"-1"
"10"
...

 so I use

strsplit(data$SiteName, split = "-")

and get

"OYS" "PIA2" "FL" "1"
"OYS" "PIA2" "LA" "1"
"OYS" "PI" "LA" "BB" "1"
"OYS" "PIA2" "LA" "10"
...

which is great.  Unfortunately, I'm stuck.  I don't know how to
retrieve the final grouping of information from the strsplit()
statement I called into a new column.

Can you help?

Thanks -

SR
Steven H. Ranney

__
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] query multiple terms in PubMed abstract

2012-12-11 Thread David Winsemius


On Dec 11, 2012, at 6:42 AM, email wrote:


Hi:

I am trying to search PubMed abstracts which contains BOTH two terms:
COL4A1 AND Ocular. I am using the following code:

url= "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?";
search = paste(url,
"db=pubmed&term=COL4A1+AND+Ocular[abstract]&retmax=300", sep="")
docId <- xmlTreeParse(getURL(paste(url, search, sep="")),
useInternalNodes=TRUE)


I want to get the reply where BOTH the terms exist in abstract. But  
it is

not doing that now. Any idea?


When I first load packages XML and RCurl, a step which you did not  
mention, and then use the "search" url that was constructed by that  
paste operation in a browser I get an XML output suggesting successful  
construction of a valid search. Checking against an ordinary search it  
appears that you were successful in forming a proper conjunction in  
the Pubmed search syntax.


I then wondered what your problem really was. You never really stated  
whether you were experiencing errors or not getting the correct Pubmed  
IDs or were having difficulties understanding the output.


--
David Winsemius, MD
Alameda, CA, USA

__
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] glm - predict logistic regression - entering the betas manually.

2012-12-11 Thread Greg Snow
It may be overkill, but you can specify the model pieces using the offset
function in the model, then the predictions work out (at least for my
simple trial case).  Something like:

fit <- glm( y ~ 0+offset(-1 + 2*x), family=binomial, data=data.frame(y=0,
x=0) )
predict( fit, newdata=data.frame(x=seq(-1,1, length.out=25)),
type='response' )



On Mon, Dec 10, 2012 at 7:26 PM, Raffaello Vardavas
wrote:

>
> Dear All,
>
> I know this may be a trivial question.
>
> In the past I have used glm to make logistic regressions on data. The
> output creates an object with the results of the logistic regression. This
> object can then be used to make predictions.
>
> Great.
>
> I have a different problem. I need to make predictions from a logistic
> regression taken from a paper. Thus I need to (by hand) enter the reported
> odds ratios, compute the betas and enter these into an object in order to
> use the predict.
>
> Sure, I can write a function myself (the logit function) to make these
> predictions. But I was wondering how one can do this by creating a glm
> output object by entering this  manually and then use the predict.
>
> I couldn't find any helpful site.
>
> Thanks.
>
> RAff.
>
>
> [[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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[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] Retain last grouping after a strsplit()

2012-12-11 Thread jim holtman
try this:

> x
[1] "OYS-PIA2-FL-1"  "OYS-PIA2-LA-1"  "OYS-PI-LA-BB-1" "OYS-PIA2-LA-10"
> sub("^.*?([0-9]+)$", "\\1", x)
[1] "1"  "1"  "1"  "10"
>



On Tue, Dec 11, 2012 at 12:46 PM, Steven Ranney  wrote:
> OYS-PIA2-FL-1
> OYS-PIA2-LA-1
> OYS-PI-LA-BB-1
> OYS-PIA2-LA-10



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] debug on lapply

2012-12-11 Thread Asis Hallab
Dear R experts,

recently I tried to debug a R function with an internal lapply call.
When debugging I seem not to be able to use the "n" command to debug the
inner function called by lapply.
How could I achieve this?

*For example:*
test <- function( ) {
  lapply( 1:3, function( x ) x + 1 )
}
debug( test )

*Start debug:*
> test()
debugging in: test()
debug bei #1:{
lapply(1:10, function(x) x + 1)
}
Browse[2]> n
debug bei #2:lapply(1:10, function(x) x + 1)

*The next "n" does not allow me to inspect the inner function,*
*but gives me the result directly:*
Browse[2]> n
exiting from: test()
[[1]]
[1] 2

[[2]]
[1] 3

[[3]]
[1] 4

Can anyone help me, please?
Kind regards!

[[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] Retain last grouping after a strsplit()

2012-12-11 Thread David Winsemius


On Dec 11, 2012, at 10:10 AM, jim holtman wrote:


try this:


x
[1] "OYS-PIA2-FL-1"  "OYS-PIA2-LA-1"  "OYS-PI-LA-BB-1" "OYS-PIA2- 
LA-10"

sub("^.*?([0-9]+)$", "\\1", x)

[1] "1"  "1"  "1"  "10"







Steve;

jim holtman is one of the jewels of the rhelp world. I generally  
assume that his answers are going to be the most succinct and  
efficient ones possible and avoid adding noise, but here I thought I  
would try to improve. Thinking there might be a string-splitting  
approach I first tried (and discovered a not-so-great solution:


 x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1", "OYS- 
PIA2-LA-10")

 sapply( strsplit(x, "-") , "[", 4)
[1] "1"  "1"  "BB" "10"

So then I asked myself if we could just "blank out" everything before  
the last das, finding what seemed to be a fairly economical solution  
and one that does not require back-references:


 sub( "^.+-" , "", x)
[1] "1"  "1"  "1"  "10"

If there were no digits after the last dash these approaches give  
different results:


 x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1", "OYS- 
PIA2-LA-")


 sub( "^.+-" , "", x)
[1] "1" "1" "1" ""

 sub("^.*?([0-9]+)$", "\\1", x)
[1] "1""1""1""OYS-PIA2-LA-"

When a grep pattern does not match, sub and gsub will return the whole  
argument.


--
David.



On Tue, Dec 11, 2012 at 12:46 PM, Steven Ranney > wrote:

OYS-PIA2-FL-1
OYS-PIA2-LA-1
OYS-PI-LA-BB-1
OYS-PIA2-LA-10




--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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
Alameda, CA, USA

__
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] debug on lapply

2012-12-11 Thread jim holtman
Typically when I am debugging an 'lapply', I put a browser call inside
the lapply function that is being called and then make sure I 'source'
in the code instead of copy/paste -- the copy/paste will use any
trailing statements after the lapply call as commands to the "browser"
function.

Here is the modified code I used:

lapply( 1:3, function( x ){
browser()
x + 1
}
  )



Here is the output from the console after "sourcing" in the statements above:

> source('clipboard')
Called from: FUN(1:3[[1L]], ...)
Browse[1]> ls()
[1] "x"
Browse[1]> x
[1] 1
Browse[1]> n
debug at clipboard#3: x + 1
Browse[2]> x
[1] 1
Browse[2]> n
Called from: FUN(1:3[[2L]], ...)
Browse[1]> x
[1] 2
Browse[1]> n
debug at clipboard#3: x + 1
Browse[2]>
Called from: FUN(1:3[[3L]], ...)
Browse[1]> n
debug at clipboard#3: x + 1
Browse[2]> x
[1] 3
Browse[2]> n
>


On Tue, Dec 11, 2012 at 1:17 PM, Asis Hallab  wrote:
> Dear R experts,
>
> recently I tried to debug a R function with an internal lapply call.
> When debugging I seem not to be able to use the "n" command to debug the
> inner function called by lapply.
> How could I achieve this?
>
> *For example:*
> test <- function( ) {
>   lapply( 1:3, function( x ) x + 1 )
> }
> debug( test )
>
> *Start debug:*
>> test()
> debugging in: test()
> debug bei #1:{
> lapply(1:10, function(x) x + 1)
> }
> Browse[2]> n
> debug bei #2:lapply(1:10, function(x) x + 1)
>
> *The next "n" does not allow me to inspect the inner function,*
> *but gives me the result directly:*
> Browse[2]> n
> exiting from: test()
> [[1]]
> [1] 2
>
> [[2]]
> [1] 3
>
> [[3]]
> [1] 4
>
> Can anyone help me, please?
> Kind regards!
>
> [[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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] Focus on a sub-panel of a splom with trellis.focs() -- return coordinate of sub-panel, or names of variables therein

2012-12-11 Thread Eric Stone
Hi,
I'd like to be able to generate a splom plot in R and then use my mouse to 
click on one of the sub-panels (panel.pairs, specifically) and have R return 
either the coordinates of that sub-panel, or even better, the names of the 
corresponding variables plotted in that sub-panel.

Here's an example to work with:

> library(lattice)
> splom(~iris[1:4], groups = Species, data = iris,
+   panel = panel.superpose,
+   key = list(title = "Three Varieties of Iris",
+  columns = 3, 
+  points = list(pch = super.sym$pch[1:3],
+col = super.sym$col[1:3]),
+  text = list(c("Setosa", "Versicolor", "Virginica"

This is what I've been able to come up with so far, but I know it's not what I 
need. I'd like to be able to select an entire sub-panel

> trellis.focus()
> panel.link.splom() #click on a point in the plot, then hit 'esc'

[1]  80 111

> trellis.unfocus() #to end trellis.focus

Thanks for your help,
Eric


[[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] Retain last grouping after a strsplit()

2012-12-11 Thread Steven Ranney
David and Jim -

Thanks for your help.  Your suggestions worked just fine.  Now my task
is to learn why the random-looking string of characters in the first
part of Jim's sub() statement aren't really so random.

Thanks again -

SR
Steven H. Ranney


On Tue, Dec 11, 2012 at 11:37 AM, David Winsemius
 wrote:
>
> On Dec 11, 2012, at 10:10 AM, jim holtman wrote:
>
>> try this:
>>
>>> x
>>
>> [1] "OYS-PIA2-FL-1"  "OYS-PIA2-LA-1"  "OYS-PI-LA-BB-1" "OYS-PIA2-LA-10"
>>>
>>> sub("^.*?([0-9]+)$", "\\1", x)
>>
>> [1] "1"  "1"  "1"  "10"
>>>
>>>
>>
>>
>
> Steve;
>
> jim holtman is one of the jewels of the rhelp world. I generally assume that
> his answers are going to be the most succinct and efficient ones possible
> and avoid adding noise, but here I thought I would try to improve. Thinking
> there might be a string-splitting approach I first tried (and discovered a
> not-so-great solution:
>
>  x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1",
> "OYS-PIA2-LA-10")
>  sapply( strsplit(x, "-") , "[", 4)
> [1] "1"  "1"  "BB" "10"
>
> So then I asked myself if we could just "blank out" everything before the
> last das, finding what seemed to be a fairly economical solution and one
> that does not require back-references:
>
>  sub( "^.+-" , "", x)
>
> [1] "1"  "1"  "1"  "10"
>
> If there were no digits after the last dash these approaches give different
> results:
>
>  x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1",
> "OYS-PIA2-LA-")
>
>  sub( "^.+-" , "", x)
>
> [1] "1" "1" "1" ""
>
>  sub("^.*?([0-9]+)$", "\\1", x)
> [1] "1""1""1""OYS-PIA2-LA-"
>
> When a grep pattern does not match, sub and gsub will return the whole
> argument.
>
> --
> David.
>
>>
>> On Tue, Dec 11, 2012 at 12:46 PM, Steven Ranney 
>> wrote:
>>>
>>> OYS-PIA2-FL-1
>>> OYS-PIA2-LA-1
>>> OYS-PI-LA-BB-1
>>> OYS-PIA2-LA-10
>>
>>
>>
>>
>> --
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>> __
>> 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
> Alameda, CA, USA
>

__
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] Interpretation of ranef output

2012-12-11 Thread Ginnie D Morrison
Hello.
I'm running a generalized linear model and am interested in using the
random effects that are output for further analysis. My random effect is
interacting with two different fixed effects (which which are factors with
two levels each). When I retrieve the random effects I get something like
this:
(Intercept)nutrient  (Intercept)light  (Intercept)
 Aa-0   0.59679192  0.34824858  2.241424479 -2.335037842  0.775359364
 Ag-0  -2.73719135  2.10428715 -0.980046942 -1.832587350 -1.938942967
 Ak-1  -0.13221525  1.03282635 -0.624239559  1.594044342  0.313188938
 Alc-0  1.16506640 -0.05914007  1.964024728 -1.133954211  1.190791025
 ALL1-2-1.06702524 -0.55728016 -0.019232427 -2.389703709 -1.357733079
 Alst-1-1.59281754  0.23968834 -1.506568899 -0.280839171 -1.558589679
 Amel-1 0.46083213 -0.02787653  0.885634543 -0.632460142  0.469048098

So...3 intercepts and two values for the interaction terms.
My questions are:
Which one is the straight-up intercept for the random term itself?
How do I get the predictor/estimate (basically, the BLUP) for the different
interaction levels?
Thanks,
Ginnie

[[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] Retain last grouping after a strsplit()

2012-12-11 Thread arun


HI,
You could also use:
x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1", "OYS-PIA2-LA-10")
gsub(".*\\-(\\d+)$","\\1",x)
#[1] "1"  "1"  "1"  "10"

#or 
gsub("[A-Z2-]","",x) #in this case
#[1] "1"  "1"  "1"  "10"



- Original Message -
From: Steven Ranney 
To: r-help@r-project.org
Cc: 
Sent: Tuesday, December 11, 2012 12:46 PM
Subject: [R] Retain last grouping after a strsplit()

All -

I have a column of SiteNames:

SiteName
OYS-PIA2-FL-1
OYS-PIA2-LA-1
OYS-PI-LA-BB-1
OYS-PIA2-LA-10
...
[truncated]

and I want to include only the last few digits into a new column.

I tried

substr(data$SiteName, 13, 20)

but because some SiteName values are of a different length, the final
hyphen (i.e., "-") was included:

"1"
"1"
"-1"
"10"
...

so I use

strsplit(data$SiteName, split = "-")

and get

"OYS" "PIA2" "FL" "1"
"OYS" "PIA2" "LA" "1"
"OYS" "PI" "LA" "BB" "1"
"OYS" "PIA2" "LA" "10"
...

which is great.  Unfortunately, I'm stuck.  I don't know how to
retrieve the final grouping of information from the strsplit()
statement I called into a new column.

Can you help?

Thanks -

SR
Steven H. Ranney

__
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-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] Reassign functions called by other functions in package graphics

2012-12-11 Thread John Kolassa
I am trying to get a function written in R that calls a cascade of functions 
from the graphics package, and I want to eventually call replacements to 
functions in the graphics package instead of the originals.  Specifically, I 
have a function that calls qqnorm in stats, which calls qqnorm.default in 
stats, which calls plot in graphics, which calls plot.default and plot.new, and 
I want my own functions plot.default and plot.new that I entered at the command 
line (which I guess means that it is in .GlobalEnv).  I'd like my plot.default 
and plot.new called (this afternoon, at least) in place of every invocation of 
plot.default and plot.new resp..  So far I've tried:

reassignInPackage from R.utils: 
reassignInPackage("plot.default","graphics",my.plot.default) gives "Error in 
assignInNamespaceT(name, value, ns = pkgName, envir = env) :   locked binding 
of ‘plot.default’ cannot be changed", even after
unlockBinding("plot.default",as.environment("package:graphics"))

assignInNamespace seems to almost work.  Here's what I enter:

plot.default<-function(...){cat("Entered plot.default")}
plot.new<-function(...){cat("Entered plot.new")}
assignInNamespace("plot.default",plot.default,ns="graphics")
assignInNamespace("plot.new",plot.new,ns="graphics")
qqnorm(1:10)

and here's what I get:

Entered plot.newError in plot.xy(xy, type, ...) : plot.new has not been called 
yet

It seems as though my new plot.new is being called, but the existing 
plot.default is being called, even though the new version is in 
graphics::plot.default.  I conjecture that this is because the original 
plot.default got exported when the package loaded, but is there a
 way to overwrite this?  Thanks, John

__
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] debug on lapply

2012-12-11 Thread Duncan Murdoch

On 11/12/2012 1:17 PM, Asis Hallab wrote:

Dear R experts,

recently I tried to debug a R function with an internal lapply call.
When debugging I seem not to be able to use the "n" command to debug the
inner function called by lapply.
How could I achieve this?


Jim gave you one solution.  Another is to debug lapply, and when 
stepping through it, debug(FUN) after it is created on the first line.  
Jim's method is more convenient if you are particularly interested in a 
complicated function, this method is better if you are already in the 
middle of debugging and just want to look at a possibly anonymous 
function being passed to lapply.


Duncan Murdoch


*For example:*
test <- function( ) {
   lapply( 1:3, function( x ) x + 1 )
}
debug( test )

*Start debug:*
> test()
debugging in: test()
debug bei #1:{
 lapply(1:10, function(x) x + 1)
}
Browse[2]> n
debug bei #2:lapply(1:10, function(x) x + 1)

*The next "n" does not allow me to inspect the inner function,*
*but gives me the result directly:*
Browse[2]> n
exiting from: test()
[[1]]
[1] 2

[[2]]
[1] 3

[[3]]
[1] 4

Can anyone help me, please?
Kind regards!

[[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-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] Retain last grouping after a strsplit()

2012-12-11 Thread Gabor Grothendieck
On Tue, Dec 11, 2012 at 12:46 PM, Steven Ranney  wrote:
> All -
>
> I have a column of SiteNames:
>
> SiteName
> OYS-PIA2-FL-1
> OYS-PIA2-LA-1
> OYS-PI-LA-BB-1
> OYS-PIA2-LA-10
> ...
> [truncated]
>
> and I want to include only the last few digits into a new column.
>
> I tried
>
> substr(data$SiteName, 13, 20)
>
> but because some SiteName values are of a different length, the final
> hyphen (i.e., "-") was included:
>
> "1"
> "1"
> "-1"
> "10"

Replace everything up to the last dash with the empty string like this:

sub(".*-", "", data$SiteName)

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Focus on a sub-panel of a splom with trellis.focs() -- return coordinate of sub-panel, or names of variables therein

2012-12-11 Thread ilai
You could try

require(grid)
trellis.focus()
names(iris)[round(unlist(grid.locator()))]
trellis.unfocus()

cheers

On Tue, Dec 11, 2012 at 11:59 AM, Eric Stone  wrote:

> Hi,
> I'd like to be able to generate a splom plot in R and then use my mouse to
> click on one of the sub-panels (panel.pairs, specifically) and have R
> return either the coordinates of that sub-panel, or even better, the names
> of the corresponding variables plotted in that sub-panel.
>
> Here's an example to work with:
>
> > library(lattice)
> > splom(~iris[1:4], groups = Species, data = iris,
> +   panel = panel.superpose,
> +   key = list(title = "Three Varieties of Iris",
> +  columns = 3,
> +  points = list(pch = super.sym$pch[1:3],
> +col = super.sym$col[1:3]),
> +  text = list(c("Setosa", "Versicolor", "Virginica"
>
> This is what I've been able to come up with so far, but I know it's not
> what I need. I'd like to be able to select an entire sub-panel
>
> > trellis.focus()
> > panel.link.splom() #click on a point in the plot, then hit 'esc'
>
> [1]  80 111
>
> > trellis.unfocus() #to end trellis.focus
>
> Thanks for your help,
> Eric
>
>
> [[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.
>

[[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] Retain last grouping after a strsplit()

2012-12-11 Thread David Winsemius

On Dec 11, 2012, at 11:14 AM, Steven Ranney wrote:

> David and Jim -
> 
> Thanks for your help.  Your suggestions worked just fine.  Now my task
> is to learn why the random-looking string of characters in the first
> part of Jim's sub() statement aren't really so random.
> 

Jim's solution can be read as:

Pattern matching phase:

continue along all the characters, ".*?" from the beginning "^" until you 
encounter any characters in the range "0" to "9" that are all together just 
before the end ("$"). Label or store those in-range characters as matched group 
numbered "\\1". The entire pattern will match the whole string.

Substitution phase:

Replace what is matched (the whole string in this case)  with just the first 
numbered matched group, "\\1".


Notice that this could be thought of as a "positive replacement" in contrast to 
my solution and Gabor Grothendieck's later and slightly more compact version 
which could be called "negative replacements".
-- 
David

> Thanks again -
> 
> SR
> Steven H. Ranney
> 
> 
> On Tue, Dec 11, 2012 at 11:37 AM, David Winsemius
>  wrote:
>> 
>> On Dec 11, 2012, at 10:10 AM, jim holtman wrote:
>> 
>>> try this:
>>> 
 x
>>> 
>>> [1] "OYS-PIA2-FL-1"  "OYS-PIA2-LA-1"  "OYS-PI-LA-BB-1" "OYS-PIA2-LA-10"
 
 sub("^.*?([0-9]+)$", "\\1", x)
>>> 
>>> [1] "1"  "1"  "1"  "10"
 
 
>>> 
>>> 
>> 
>> Steve;
>> 
>> jim holtman is one of the jewels of the rhelp world. I generally assume that
>> his answers are going to be the most succinct and efficient ones possible
>> and avoid adding noise, but here I thought I would try to improve. Thinking
>> there might be a string-splitting approach I first tried (and discovered a
>> not-so-great solution:
>> 
>> x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1",
>> "OYS-PIA2-LA-10")
>> sapply( strsplit(x, "-") , "[", 4)
>> [1] "1"  "1"  "BB" "10"
>> 
>> So then I asked myself if we could just "blank out" everything before the
>> last das, finding what seemed to be a fairly economical solution and one
>> that does not require back-references:
>> 
>> sub( "^.+-" , "", x)
>> 
>> [1] "1"  "1"  "1"  "10"
>> 
>> If there were no digits after the last dash these approaches give different
>> results:
>> 
>> x <- c("OYS-PIA2-FL-1",  "OYS-PIA2-LA-1",  "OYS-PI-LA-BB-1",
>> "OYS-PIA2-LA-")
>> 
>> sub( "^.+-" , "", x)
>> 
>> [1] "1" "1" "1" ""
>> 
>> sub("^.*?([0-9]+)$", "\\1", x)
>> [1] "1""1""1""OYS-PIA2-LA-"
>> 
>> When a grep pattern does not match, sub and gsub will return the whole
>> argument.
>> 
>> --
>> David.
>> 
>>> 
>>> On Tue, Dec 11, 2012 at 12:46 PM, Steven Ranney 
>>> wrote:
 
 OYS-PIA2-FL-1
 OYS-PIA2-LA-1
 OYS-PI-LA-BB-1
 OYS-PIA2-LA-10
>>> 
>>> 
>>> 
>>> 
>>> --
>>> Jim Holtman
>>> Data Munger Guru
>>> 
>>> What is the problem that you are trying to solve?
>>> Tell me what you want to do, not how you want to do it.
>>> 
>>> __
>>> 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
>> Alameda, CA, USA
>> 

David Winsemius
Alameda, CA, USA

__
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] Solving Simultaneous nonlinear equations

2012-12-11 Thread Rajibul Mian
Dear:

I am having trouble solving simultaneous nonlinear equations by R. I have
been using BBsolve (BB) to do so. Though the function is very strong, still
the program doesn't converge. I have tried all (according to my small
knowledge) the options described in the help file.

Now I am trying to find something else than BBsolve for solving
simultaneous nonlinear equations by R. Any idea or suggestion would be
highly appreciable. Thanks.

Best.
Rajibul Mian
Grad Student, Maths & STATS,
UWindsor, Canada.

[[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] Interpretation of ranef output

2012-12-11 Thread Ben Bolker
Ginnie D Morrison  utexas.edu> writes:


> I'm running a generalized linear model 

  Note that this is a generalized linear *mixed* model, which 
complicates the situation somewhat (otherwise you wouldn't
be dealing with random effects).  Presumably you are using
glmer from the lme4 package, but it would be good to state that
explicitly ...


> and am interested in using the
> random effects that are output for further analysis. My random effect is
> interacting with two different fixed effects (which which are factors with
> two levels each). When I retrieve the random effects I get something like
> this:
>(Intercept)nutrient  (Intercept)light  (Intercept)
>  Aa-0   0.59679192  0.34824858  2.241424479 -2.335037842  0.775359364
>  Ag-0  -2.73719135  2.10428715 -0.980046942 -1.832587350 -1.938942967
>  Ak-1  -0.13221525  1.03282635 -0.624239559  1.594044342  0.313188938
>  Alc-0  1.16506640 -0.05914007  1.964024728 -1.133954211  1.190791025
>  ALL1-2-1.06702524 -0.55728016 -0.019232427 -2.389703709 -1.357733079
>  Alst-1-1.59281754  0.23968834 -1.506568899 -0.280839171 -1.558589679
>  Amel-1 0.46083213 -0.02787653  0.885634543 -0.632460142  0.469048098
> 
> So...3 intercepts and two values for the interaction terms.


  You should probably specify your random effect as

 ... (1|grpFactor) + (0 + nutrient|grpFactor) + (0 + light|grpFactor)
to avoid having the intercept terms estimated separately ...  my guess
is that the model is overspecified.

> My questions are:
> Which one is the straight-up intercept for the random term itself?
> How do I get the predictor/estimate (basically, the BLUP) for the different
> interaction levels?

  In the same way that you would combine coefficients from a standard
linear model to get predicted values for specific cases.  We probably
need a little more context about the experimental design.  
  
  Followups to r-sig-mixed-mod...@r-project.org, please ...

__
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] Solving Simultaneous nonlinear equations

2012-12-11 Thread Berend Hasselman

On 11-12-2012, at 21:10, Rajibul Mian wrote:

> Dear:
> 
> I am having trouble solving simultaneous nonlinear equations by R. I have
> been using BBsolve (BB) to do so. Though the function is very strong, still
> the program doesn't converge. I have tried all (according to my small
> knowledge) the options described in the help file.
> 
> Now I am trying to find something else than BBsolve for solving
> simultaneous nonlinear equations by R. Any idea or suggestion would be
> highly appreciable. Thanks.


package nleqslv.

Also mentioned in Task View Optimization.

Berend

__
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] Latitudinal mean of values in a data frame

2012-12-11 Thread S.N.Manohar
Thank you very much for all those solutions.

On 11-12-12, David Winsemius   wrote:
> 
> On Dec 11, 2012, at 3:17 AM, Swagath Navin wrote:
> 
> >Dear all,
> >
> >I have a big file containing latitude points(-10 to 80) and corresponding 
> >values.
> >Example data
> >
> >Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 69.53746, 
> >69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 70.00106, 70.00295, 
> >70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 70.01049, 70.01053, 
> >70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 70.01646, 70.01983, 
> >70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 70.02856, 70.0291, 
> >70.02983, 70.03091, 70.03267, 70.03423)
> >
> >Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 
> >0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 
> >0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 
> >0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 0.14388486, 
> >0.19098477, 0.17252013, 0.12965086, 0.12256515, 0.18159349, 0.15608113, 
> >0.18742996, 0.13858418, 0.16865459, 0.19058037, 0.12531143, 0.19189732, 
> >0.12019097, 0.1790819, 0.15086053, 0.18607724,  0.13330366)
> >
> >dframe=data.frame(Lat, Value)
> >
> >i would like to find latitudinal mean such that my output looks like the 
> >below:
> >
> >Lat Value
> >69 0.18
> >70 0.16
> 
> ?trunc   # some people prefer floor()
> ?tapply
> 
> -- 
> 
> David Winsemius, MD
> Alameda, CA, USA
> 
> 
>

[[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] questions on French characters in plot

2012-12-11 Thread Richard Zijdeman
Dear Milan, please see my results inline

On 11 Dec 2012, at 16:58, Milan Bouchet-Valat  wrote:

> Le mardi 11 décembre 2012 à 16:41 +0100, Richard Zijdeman a écrit :
>> Dear Milan,
>> 
>> thank you for kind suggestion. Converting the characters using:
>>> iconv(department, "ISO-8859-15", "UTF-8")
>> indeed improves the situation in that now all values (names of
>> departments) are displayed in the plot, although the specific special
>> characters are unfortunately appearing as empty boxes.
> I wouldn't call that an improvement... :-/
> 
> What's the result of the other one, i.e.
> iconv(department, "UTF-16", "UTF-8")

That does not change the outcome, i.e. the names of departments with special 
characters are not plotted at all.

> 
>> I have tried to see whether I could 'save' my state file using UTF-8
>> format, and although this proves to be a popular request it does not
>> seem to have been incorporated in Stata.
> You should not need this. iconv() should be able to convert the strings
> to something usable. The problem is to determine what's the original
> encoding. Could you call
> lapply(department, charToRaw)
> 
> and post the output?

Thanks for providing another suggestions. I have selected 3 cases from the 
dataset I am working with that are problematic and have made new vars based on 
the iconv conversion. The department variable is called 'liac' and I now have 
next to the original three different versions based on the the UTF16, 
ISO-8859-1 and ISO-8859-15 conversion. I hope I executed it properly, but there 
seems to be an error when executing your code on the original variable.

## start results
> head(tra.s)
 liacliac2liac3  liac1
18 Ard\x8fche Ard\u008fche Ard\u008fche   
29 Corr\x8fze Corr\u008fze Corr\u008fze   
31  Vend\x8ee  Vend\u008ee  Vend\u008ee 噥湤蹥
> lapply(tra.s$liac,charToRaw) # original (stata import)
Error in FUN(X[[1L]], ...) : 
  argument must be a character vector of length 1
> lapply(tra.s$liac1, charToRaw) # UTF16 -> UTF-8
[[1]]
[1] 4e 41

[[2]]
[1] 4e 41

[[3]]
[1] e5 99 a5 e6 b9 a4 e8 b9 a5

> lapply(tra.s$liac2, charToRaw) # ISO-8859-1 -> UTF-8
[[1]]
[1] 41 72 64 c2 8f 63 68 65

[[2]]
[1] 43 6f 72 72 c2 8f 7a 65

[[3]]
[1] 56 65 6e 64 c2 8e 65

> lapply(tra.s$liac3, charToRaw) # ISO-8859-15 -> UTF-8
[[1]]
[1] 41 72 64 c2 8f 63 68 65

[[2]]
[1] 43 6f 72 72 c2 8f 7a 65

[[3]]
[1] 56 65 6e 64 c2 8e 65
## end results

Best wishes and thanks,

Richard

> 
> 
> Regards
> 
>> Best and thank you for your help,
>> 
>> Richard
>> 
>> 
>> On 11 Dec 2012, at 12:11, Milan Bouchet-Valat  wrote:
>> 
>>> Le mardi 11 décembre 2012 à 01:10 +0100, Richard Zijdeman a écrit :
 Dear all,
 
 I have imported a dataset from Stata using the foreign package. The
 original data contain French characters such as  and  .
 After importing, string variables containing names of French
 departments have changed. E.g. Ardche became Ard\x8fche. I would like
 to ask how I could plot these changed strings, since now the strings
 with special characters fail to be printed in the plot (either using
 plot() or ggplot2()).
 
 I have googled for solutions, but actually find it hard to determine
 whether I should change my R setup or should read in the data in a
 different way. Since I work on a mac I changed my local according to
 the R for Mac OS X FAQ, chapter 9.  Below is some info on my setup and
 code and output on what works for me and what does not. Thank you in
 advance for you comments.
>>> Accentuated characters should work fine on a machine using a UTF-8
>>> locale as yours. I think the problem is that the imported data uses
>>> ISO8859-15 or UTF-16, not UTF-8.
>>> 
>>> I have no idea whether .dta files specify an encoding or not, but I
>>> think you can convert them in R by calling
>>> iconv(department, "ISO-8859-15", "UTF-8")
>>> or
>>> iconv(department, "UTF-16", "UTF-8")
>>> 
 Best,
 
 Richard
 
 #--
 rm(list=ls())
 sessionInfo()
 # R version 2.15.2 (2012-10-26)
 # Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
 #
 # locale:
 # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
 
 # creating variables
 department  <- c("Nord","Paris","Ard\x8fche")
>>> \x8 does not correspond to "è" AFAIK. In ISO8859-1 and -15 and UTF-16,
>>> it's \xE8 ("\uE8" in R).
>>> 
>>> In UTF-8, it's C3 A8, "\303\250" in R.
>>> 
 department2 <- c("Nord", "Paris", "Ardche")
 n   <- c(2,4,1)
 
 # creating dataframes
 df  <- data.frame(department,n)
 df2 <- data.frame(department2,n)
 
 department
 # [1] "Nord"   "Paris"  "Ard\x8fche"
 department2
 # [1] "Nord""Paris"   "Ardche"
 
 plot(df) # fails to show the text "Ardche"
 plot(df2) # shows text "Ardche"
 
 # EOF
[[alternative HTML version deleted]]
 
 __
>

[R] Rprof causing R to crash

2012-12-11 Thread Marian Talbert
I'm trying to use Rprof() to identify bottlenecks and speed up a particullary
slow section of code which reads in a portion of a tif file and compares
each of the values to values of predictors used for model fitting.  I've
written up an example that anyone can run.  Generally temp would be a
section of a tif read into a data.frame and used later for other processing. 
The first portion which just records the time works in about 6 seconds the
second part causes RGui to immediately close with no error or warning.  Any
advice on how to get Rprof to work or how to speed up this code would be
greatly appreciated.  I'm using Windows 7 (which might be my problem) and R
version 2.15.0.  

CalcMESS<-function(tiff.entry,pred.vect){
  f<-sum(pred.vecthttp://r.789695.n4.nabble.com/Rprof-causing-R-to-crash-tp4652846.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] questions on French characters in plot

2012-12-11 Thread Duncan Murdoch

On 12-12-10 7:10 PM, Richard Zijdeman wrote:

Dear all,

I have imported a dataset from Stata using the foreign package. The original 
data contain French characters such as è and ç .
After importing, string variables containing names of French departments have 
changed. E.g. Ardèche became Ard\x8fche. I would like to ask how I could plot 
these changed strings, since now the strings with special characters fail to be 
printed in the plot (either using plot() or ggplot2()).


As Milan as said, it's an encoding problem. I don't know any encoding 
that represents a "è" character by \x8f, but if it does that 
consistently, you can fix it pretty easily:


> x
[1] "Ard\x8fche"

> x <- sub("\x8f", "è", x, useBytes=TRUE)
> x
[1] "Ardèche"

You'll have to read the results pretty carefully to make sure you catch 
all the corrections (and to make sure they are done correctly), but you 
should be able to fix things.


Duncan Murdoch



I have googled for solutions, but actually find it hard to determine whether I 
should change my R setup or should read in the data in a different way. Since I 
work on a mac I changed my local according to the R for Mac OS X FAQ, chapter 
9.  Below is some info on my setup and code and output on what works for me and 
what does not. Thank you in advance for you comments.

Best,

Richard

#--
rm(list=ls())
sessionInfo()
# R version 2.15.2 (2012-10-26)
# Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
#
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

# creating variables
department  <- c("Nord","Paris","Ard\x8fche")
department2 <- c("Nord", "Paris", "Ardèche")
n   <- c(2,4,1)

# creating dataframes
df  <- data.frame(department,n)
df2 <- data.frame(department2,n)

department
# [1] "Nord"   "Paris"  "Ard\x8fche"
department2
# [1] "Nord""Paris"   "Ardèche"

plot(df) # fails to show the text "Ardèche"
plot(df2) # shows text "Ardèche"

# EOF
[[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-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] Multiple palettes on single plot don't get rendered when I use dev.copy2pdf

2012-12-11 Thread Andrew Crane-Droesch

Hi All,

I'm having trouble with the colors on my screen getting translated to 
the colors in the outputted .pdf document.


Here is a caricature of my problem:

par(mfrow=c(1,1))
x1 = rnorm(1000)
x2 = rnorm(1000)+10
y1 = rnorm(1000)+10
y2 = rnorm(1000)+10
palette(rainbow(6))
plot(x=x1,y=y1,col=y1,xlim=c(-10,20))

palette(heat.colors(6))
points(x=x2,y=y2,col=y2)

dev.copy2pdf(file = "broke.pdf", height = 8, width = 8)

I plot the two normal blobs in two different color palettes, and it 
looks fine on the screen.  I go to look at the PDF, and they are BOTH in 
heat map.


How would I render both palettes on the pdf?

Many thanks,
Andrew

__
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] Multiple palettes on single plot don't get rendered when I use dev.copy2pdf

2012-12-11 Thread arun
Hi,
Try this:
 pdf("broke.pdf")
 palette(rainbow(6))
 plot(x=x1,y=y1,col=y1,xlim=c(-10,20))
 palette(heat.colors(6))
 points(x=x2,y=y2,col=y2)
 dev.off()
A.K.



- Original Message -
From: Andrew Crane-Droesch 
To: R help 
Cc: 
Sent: Tuesday, December 11, 2012 7:17 PM
Subject: [R] Multiple palettes on single plot don't get rendered when I use 
dev.copy2pdf

Hi All,

I'm having trouble with the colors on my screen getting translated to the 
colors in the outputted .pdf document.

Here is a caricature of my problem:

par(mfrow=c(1,1))
x1 = rnorm(1000)
x2 = rnorm(1000)+10
y1 = rnorm(1000)+10
y2 = rnorm(1000)+10
palette(rainbow(6))
plot(x=x1,y=y1,col=y1,xlim=c(-10,20))

palette(heat.colors(6))
points(x=x2,y=y2,col=y2)

    dev.copy2pdf(file = "broke.pdf", height = 8, width = 8)

I plot the two normal blobs in two different color palettes, and it looks fine 
on the screen.  I go to look at the PDF, and they are BOTH in heat map.

How would I render both palettes on the pdf?

Many thanks,
Andrew

__
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-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] Multiple palettes on single plot don't get rendered when I use dev.copy2pdf

2012-12-11 Thread Andrew Crane-Droesch
Thanks a lot!  This works, provided I run my version first.  For 
posterity, the following does what is wanted:


par(mfrow=c(1,1))
x1 = rnorm(1000)
x2 = rnorm(1000)+10
y1 = rnorm(1000)+10
y2 = rnorm(1000)+10
palette(rainbow(6))
plot(x=x1,y=y1,col=y1,xlim=c(-10,20))

palette(heat.colors(6))
points(x=x2,y=y2,col=y2)

dev.copy2pdf(file = "broke.pdf", height = 8, width = 8)


 pdf("broke.pdf")
 palette(rainbow(6))
 plot(x=x1,y=y1,col=y1,xlim=c(-10,20))
 palette(heat.colors(6))
 points(x=x2,y=y2,col=y2)
 dev.off()


On 12/11/2012 04:48 PM, arun wrote:

Hi,
Try this:
  pdf("broke.pdf")
  palette(rainbow(6))
  plot(x=x1,y=y1,col=y1,xlim=c(-10,20))
  palette(heat.colors(6))
  points(x=x2,y=y2,col=y2)
  dev.off()
A.K.



- Original Message -
From: Andrew Crane-Droesch 
To: R help 
Cc:
Sent: Tuesday, December 11, 2012 7:17 PM
Subject: [R] Multiple palettes on single plot don't get rendered when I use 
dev.copy2pdf

Hi All,

I'm having trouble with the colors on my screen getting translated to the 
colors in the outputted .pdf document.

Here is a caricature of my problem:

par(mfrow=c(1,1))
x1 = rnorm(1000)
x2 = rnorm(1000)+10
y1 = rnorm(1000)+10
y2 = rnorm(1000)+10
palette(rainbow(6))
plot(x=x1,y=y1,col=y1,xlim=c(-10,20))

palette(heat.colors(6))
points(x=x2,y=y2,col=y2)

 dev.copy2pdf(file = "broke.pdf", height = 8, width = 8)

I plot the two normal blobs in two different color palettes, and it looks fine 
on the screen.  I go to look at the PDF, and they are BOTH in heat map.

How would I render both palettes on the pdf?

Many thanks,
Andrew

__
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-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] Reassign functions called by other functions in package graphics

2012-12-11 Thread Greg Snow
I think the error is because the other functions are expecting the plot.new
function to do some specific things to set up the graphics device for a new
plot, but your function did not do those things.

You might consider the trace function as an alternative to what you are
trying.  It can be used to insert additional code into existing functions,
or replace them altogether.


On Tue, Dec 11, 2012 at 12:32 PM, John Kolassa wrote:

> I am trying to get a function written in R that calls a cascade of
> functions from the graphics package, and I want to eventually call
> replacements to functions in the graphics package instead of the originals.
>  Specifically, I have a function that calls qqnorm in stats, which calls
> qqnorm.default in stats, which calls plot in graphics, which calls
> plot.default and plot.new, and I want my own functions plot.default and
> plot.new that I entered at the command line (which I guess means that it is
> in .GlobalEnv).  I'd like my plot.default and plot.new called (this
> afternoon, at least) in place of every invocation of plot.default and
> plot.new resp..  So far I've tried:
>
> reassignInPackage from R.utils:
> reassignInPackage("plot.default","graphics",my.plot.default) gives "Error
> in assignInNamespaceT(name, value, ns = pkgName, envir = env) :   locked
> binding of ‘plot.default’ cannot be changed", even after
> unlockBinding("plot.default",as.environment("package:graphics"))
>
> assignInNamespace seems to almost work.  Here's what I enter:
>
> plot.default<-function(...){cat("Entered plot.default")}
> plot.new<-function(...){cat("Entered plot.new")}
> assignInNamespace("plot.default",plot.default,ns="graphics")
> assignInNamespace("plot.new",plot.new,ns="graphics")
> qqnorm(1:10)
>
> and here's what I get:
>
> Entered plot.newError in plot.xy(xy, type, ...) : plot.new has not been
> called yet
>
> It seems as though my new plot.new is being called, but the existing
> plot.default is being called, even though the new version is in
> graphics::plot.default.  I conjecture that this is because the original
> plot.default got exported when the package loaded, but is there a
>  way to overwrite this?  Thanks, John
>
> __
> 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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[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] Bayesian Haplotype analysisin R

2012-12-11 Thread knouri
Dear members:
Could you please tell me the package for Bayesian haplotype estimation  in R.
Currently PHASE is available for such purpose but I need a similar R package.

Best regards,



Keramat Nourijelyani, PhD
Associate Professorof Biostatistics
Tehran University of Medical Sciences
http://tums.ac.ir/faculties/nourij

[[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] long margin text below lattice plot - how to wrap lines?

2012-12-11 Thread knallgrau
Hello,

I've got a lattice plot and need to add text into the bottom margin of the 
plotting area (below the bottom legend). 
This seems to work in principle using grid.arrange, yet the text to be added is 
rather long. As a consequence, it gets clipped:

require(lattice)
require(grid)
myplot <- xyplot(1~1)
mytext <- textGrob("This is such a very very long text that it goes on forever 
and therefore needs to be wrapped in order for someone to be able to read it 
properly.")
grid.arrange(myplot, sub=mytext)

Is there any way to wrap the lines of the text or some other of workaround to 
this problem?

I've tried figuring it out myself, but it's a rather urgent problem and 
therefore I was hoping to find some help here.

Best,
Irene

__
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] long margin text below lattice plot - how to wrap lines?

2012-12-11 Thread Pascal Oettli

Hello

You can insert \n in your text.

mytext <- textGrob("This is such a very very long text\n that it goes on 
forever and therefore needs to be wrapped in order\n for someone to be 
able to read it properly.")


HTH
Pascal


Le 12/12/2012 16:22, knallg...@gmx.com a écrit :

Hello,

I've got a lattice plot and need to add text into the bottom margin of the 
plotting area (below the bottom legend).
This seems to work in principle using grid.arrange, yet the text to be added is 
rather long. As a consequence, it gets clipped:

require(lattice)
require(grid)
myplot <- xyplot(1~1)
mytext <- textGrob("This is such a very very long text that it goes on forever and 
therefore needs to be wrapped in order for someone to be able to read it properly.")
grid.arrange(myplot, sub=mytext)

Is there any way to wrap the lines of the text or some other of workaround to 
this problem?

I've tried figuring it out myself, but it's a rather urgent problem and 
therefore I was hoping to find some help here.

Best,
Irene

__
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-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] remove last row of a data frame

2012-12-11 Thread e-letter
Readers,

For a data set 'a':

1
2
3
4

Please what is the syntax to remove the last row and create a new object 'b':

1
2
3

Thanks.

--
R2151

__
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] Matrix multiplication

2012-12-11 Thread annek
Hi, 
I have a transition matrix T for which I want to find the steady state matrix 
for. This could be approximated by taking T^n , for large n. 

T= [ 0.8797   0.0382   0.0527   0.0008
  0.02120.8002   0.0041   0.0143
  0.09810.0273   0.8802   0.0527
  0.00100.1343   0.0630   0.9322]

According to a text book I have T^200 should have reached the steady state L

L =[0.17458813   0.17458813   0.17458813   0.17458813
  0.05731902   0.05731902   0.05731902   0.05731902
  0.35028624   0.35028624   0.35028624   0.35028624
  0.44160126   0.44160126   0.44160126   0.44160126]

I am addressing the problem using a for loop doing matrix multiplication (guess 
there might be better ways, please suggest) and find a steady state matrix 
after n=30. But if I run the code with n=100 or more I get "Inf" for all 
entities in L. Does anyone know why is that?

The code I use look like this
#
rep<-20

T <- Ttest
for(i in 1:rep){
 print(i)
 T<-T%*%Ttest
 Ttest<-T
}
L<-T
print(L)
#--
__
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] long margin text below lattice plot - how to wrap lines?

2012-12-11 Thread Irene Prix
Thanks a million!

> - Original Message -
> From: Pascal Oettli
> Sent: 12/12/12 09:37 AM
> To: knallg...@gmx.com
> Subject: Re: [R] long margin text below lattice plot - how to wrap lines?
> 
> Hello
> 
> You can insert \n in your text.
> 
> mytext <- textGrob("This is such a very very long text\n that it goes on 
> forever and therefore needs to be wrapped in order\n for someone to be 
> able to read it properly.")
> 
> HTH
> Pascal
> 
> 
> Le 12/12/2012 16:22, knallg...@gmx.com a écrit :
> > Hello,
> >
> > I've got a lattice plot and need to add text into the bottom margin of the 
> > plotting area (below the bottom legend).
> > This seems to work in principle using grid.arrange, yet the text to be 
> > added is rather long. As a consequence, it gets clipped:
> >
> > require(lattice)
> > require(grid)
> > myplot <- xyplot(1~1)
> > mytext <- textGrob("This is such a very very long text that it goes on 
> > forever and therefore needs to be wrapped in order for someone to be able 
> > to read it properly.")
> > grid.arrange(myplot, sub=mytext)
> >
> > Is there any way to wrap the lines of the text or some other of workaround 
> > to this problem?
> >
> > I've tried figuring it out myself, but it's a rather urgent problem and 
> > therefore I was hoping to find some help here.
> >
> > Best,
> > Irene
> >
> > __
> > 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-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] remove last row of a data frame

2012-12-11 Thread Daniel Nordlund
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of e-letter
> Sent: Tuesday, December 11, 2012 11:45 PM
> To: r-help@r-project.org
> Subject: [R] remove last row of a data frame
> 
> Readers,
> 
> For a data set 'a':
> 
> 1
> 2
> 3
> 4
> 
> Please what is the syntax to remove the last row and create a new object
> 'b':
> 
> 1
> 2
> 3
> 
> Thanks.
> 

If by data set a you mean a data frame called a, then something like this 
should work:

b <- a[-nrow(a),]

If you haven't already read the manual, "An Introduction to R", that ships with 
every copy of R, then now is the time.


hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
 

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