[R] Web scraping - Having trouble figuring out how to approach this problem

2017-02-23 Thread henrique monte
Sometimes I need to get some data from the web organizing it into a
dataframe and waste a lot of time doing it manually. I've been trying to
figure out how to optimize this proccess, and I've tried with some R
scraping approaches, but couldn't get to do it right and I thought there
could be an easier way to do this, can anyone help me out with this?

Fictional example:

Here's a webpage with countries listed by continents:
https://simple.wikipedia.org/wiki/List_of_countries_by_continents

Each country name is also a link that leads to another webpage (specific of
each country, e.g. https://simple.wikipedia.org/wiki/Angola).

I would like as a final result to get a data frame with number of
observations (rows) = number of countries listed and 4 variables (colums)
as ID=Country Name, Continent=Continent it belongs to, Language=Official
language (from the specific webpage of the Countries) and Population = most
recent population count (from the specific webpage of the Countries).

...

The main issue I'm trying to figure out is handling several webpages, like,
would it be possible to scrape from the first link of the problem the
countries as a list with the links of the countries webpages and then
create and run a function to run a scraping command in each of those links
from the list to get the specific data I'm looking for?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] replace NAs in each column of a matrix with 0 or 1 or 2 with specific proportion

2016-06-06 Thread Henrique Dallazuanna
Maybe you can use something like this

In this way, almost your proportion of 0, 1 and 2 will be maintained

m <- matrix(sample(c(NA, 0:2), size = 50*100, replace = TRUE), nrow = 50,
ncol = 100)
trunc(prop.table(apply(m, 2, table), 2) * colSums(is.na(m)), 0)
m[is.na(m)] <- unlist(apply(trunc(prop.table(apply(m, 2, table), 2) *
colSums(is.na(m)), 0), 2, rep, x = 0:2))

On Mon, Jun 6, 2016 at 5:38 PM, Lida Zeighami  wrote:

> Hello specialist,
>
> I have a matrix in which there are NA,0,1 and 2 in each columns.
> I wanna replace NAs with special proportion of 0,1 or 2 !
> for example in df<- matric(df, nrow=50, ncol=100)
>
> If in one column the number of NAs = 10 , # of 0=50 , #of 1=25  and # of
> 2=15
> I want to replace  5 of 10 NAs with 0 , 3 NAs with 1 and 2 NAs with 2!
>
>
> I've already calculated the proportion of 0, 1 and 2 for each column, just
> I don't know how to replace the number of NAs with these number (0,1,2) and
> specific proportion?
>
> Thank you very much in advance
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Last call internship position for working with R in Porto Alegre (RS), Brazil

2015-01-17 Thread Fernando Henrique Ferraz Pereira da Rosa
Dear all,

We are filling some positions to work with statistics (and a lot of R) in
greater Porto Alegre Area (RS), in Brazil. If you are interested please see
more details here:
https://www.facebook.com/photo.php?fbid=10152750369209601&set=a.10151426344089601.1073741828.518839600&type=1
, here:
https://plus.google.com/+FernandoHenriqueFerrazPereiradaRosa/posts/p/pub or
here:
https://www.linkedin.com/pulse/last-call-internship-position-data-science-fernando-henrique-rosa
.

Thank you and a nice Rweekend for everyone.

-- 
"Though this be randomness, yet there is structure in't."
Fernando H Rosa - Statistician
http://www.fernandohrosa.com.br / http://www.feferraz.net - Estatística,
Matemática e Computação
AprendaAlemao.net <http://aprendaalemao.net/> - Seu ponto de partida para
melhorar seu Alemão!
@fhrosa

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Deploying R in a corporate environment

2014-06-10 Thread Fernando Henrique Ferraz Pereira da Rosa
Dear all,

We have recently prepared a video for a presentation on the R User
Conference in Korea (http://rconference.itdaily.kr/). After the
presentation on the congress and getting the proper approvals from my
employer, I'd like to share the video with r-help .

https://www.youtube.com/watch?v=oS_F1KwTMOY&feature=youtu.be

Share and enjoy :)

-- 
"Though this be randomness, yet there is structure in't."
Fernando H Rosa - Statistician
http://www.fernandohrosa.com.br / http://www.feferraz.net - Estatística,
Matemática e Computação
AprendaAlemao.net  - Seu ponto de partida para
melhorar seu Alemão!
@fhrosa

[[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 a list of loglin terms to a model formula

2013-07-03 Thread Henrique Dallazuanna
Try this:

 as.formula(sprintf(" ~ %s", do.call(paste, c(lapply(mutual(3), paste,
collapse = ":"), sep = "+"



On Wed, Jul 3, 2013 at 6:55 PM, Michael Friendly  wrote:

> I'm developing some functions to create symbolic specifications for
> loglinear models of different types.
> I don't really know how to 'compute' with model formulas, so I've done
> this in the notation
> for stats::loglin(), which is a list of high-order terms in the model.
>
> What I'd like is a function to turn the results of these into a model
> formula, suitable for
> MASS::loglm.  That's the reverse of what loglm does.
>
> For example, the simplest versions of models for 3-way tables for joint,
>  conditional, and marginal independence can be computed as follows. After
> each, I indicated
> the WANTED model formula I'd like from the result
>
> > joint(3)
> $term1
> [1] 1 2
>
> $term2
> [1] 3
>
> WANTED:  ~ 1:2 + 3
>
> > condit(3)
> $term1
> [1] 1 3
>
> $term2
> [1] 2 3
>
> WANTED: ~ 1:2 + 2:3
>
> > mutual(3)
> $term1
> [1] 1
>
> $term2
> [1] 2
>
> $term3
> [1] 3
>
> WANTED: ~ 1 + 2 + 3
>
> In case anyone want to play with the code, here are the current, not too
> elegant definitions
> of the functions, and some further test cases,
>
> # models of joint independence
>   joint <- function(nf, factors=1:nf, with=nf) {
> if (nf == 1) return (list(term1=factors[1]))
> if (nf == 2) return (list(term1=factors[1], term2=factors[2]))
> others <- setdiff(1:nf, with)
> result <- list(term1=factors[others], term2=factors[with])
> result
>   }
> # conditional independence
>   condit <- function(nf, factors=1:nf, with=nf) {
> if (nf == 1) return (list(term1=factors[1]))
> if (nf == 2) return (list(term1=factors[1], term2=factors[2]))
> main <- setdiff(1:nf, with)
> others <- matrix(factors[with], length(with), length(main))
> result <- rbind(factors[main], others)
> result <- as.list(as.data.frame(result, stringsAsFactors=FALSE))
> names(result) <- paste('term', 1:length(result), sep='')
> result
>   }
> # mutual independence
>   mutual <- function(nf, factors=1:nf) {
> result <- sapply(factors[1:nf], list)
> names(result) <- paste('term', 1:length(result), sep='')
> result
>   }
>
> ### some comparisons
>
> loglin(HairEyeColor, list(c(1, 2), c(1, 3), c(2, 3)))$lrt
> loglm(~1:2 + 1:3 +2:3, HairEyeColor)
>
> # use factor names
> joint(3, factors=names(dimnames(**HairEyeColor)))
> condit(3, factors=names(dimnames(**HairEyeColor)))
>
> loglin(HairEyeColor, joint(3))$lrt
> loglm(~1:2 + 3, HairEyeColor)
>
> loglin(HairEyeColor, condit(3))$lrt
> loglm(~1:3 + 2:3, HairEyeColor)
>
>
>
> --
> Michael Friendly Email: friendly AT yorku DOT ca
> Professor, Psychology Dept. & Chair, Quantitative Methods
> York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
> 4700 Keele StreetWeb:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>
> __**
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/**
> posting-guide.html <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Course

2012-08-28 Thread Pedro Henrique Lamarão Souza
 

Hello, 

I am a student of Materials Engineering and I want to minister an
introductory course of R at the university I study here in Brazil. I know R is
a free software, but I just want to know if I do need a special authorization
for doing it. The course will be totaly free and I also will not receive any
money for doing it. The idea is just to show the program. 

--


Atenciosamente,
Pedro Lamarão
ITEC/UFPA/PPGEM/GPEMAT
 
[[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] Saving Splitted Series to Excel via XLConnect

2012-08-08 Thread Henrique Andrade
Dear Rui and David,

Thanks a lot for your help and advices. Now finally I have
what I want ;-) The final code looks like this:



dados <- data.frame(matrix(c("2012-01-01","2012-02-01",
  "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
  "2012-01-01","2012-02-01","2012-03-01","2012-04-01",
  "2012-05-01","2012-06-01","2012-01-01","2012-02-01",
  "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
  0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,
  158356,162157,166226,33.47,34.48,35.24,38.42,35.33,
  34.43,433,433,433,433,433,433,2005,2005,2005,2005,
  2005,2005,3939,3939,3939,3939,3939,3939),nrow=18,
  ncol=3,byrow=FALSE,dimnames=list(c(1,2,3,4,5,6,7,8,9,
  10,11,12,13,14,15,16,17,18),c("date","value","code"

dados2 <- split(dados, dados$code)

library(XLConnect)

wb <- loadWorkbook("Henrique.xlsx", create = TRUE)
series <- seq_along(dados2)
createSheet(wb, name = "Planilha")

lapply(series, function(i){
column <- (3*i) - 2
writeWorksheet(wb, dados2[[i]], sheet = "Planilha",
startCol = column)})
saveWorkbook(wb)



I did not use the option to build a new sheet for each "i"
because I have more than 200 objects in my real problem.

Again, many thanks to you guys!

Best regards (or "Um abraço"),
Henrique Andrade


2012/8/8 Rui Barradas :
> Hello,
>
> First of all, apologies to Henrique, he'll receive th same answer twice, but
> I forgot to Cc the list.
>
>
> In order to write 3 worksheets you need to create 3 worksheets. What
> happened is that you were overwriting the previous sheets and ended up just
> with the last one. So adopt a different method: lapply().
>
>
> wb <- loadWorkbook("Teste.xlsx", create = TRUE)
>
> series <- seq_along(dados2)
> sheet <- paste0("Teste", series)
> lapply(series, function(i){
> createSheet(wb, name = sheet[i])
> writeWorksheet(wb, dados2[[i]], sheet = sheet[i])})
>
> saveWorkbook(wb)
>
> This worked with me.
>
> Hope this helps,
>
> Rui Barradas
> Em 08-08-2012 21:10, Henrique Andrade escreveu:
>>
>> Dear R Discussion List,
>>
>>
>> I would like to save my data as a xlsx file. But at first
>> I need to split it and then save each series into a Excel
>> column. Please take a look at the following code:
>>
>> dados <- data.frame(matrix(c("2012-01-01","2012-02-01",
>>"2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>>"2012-01-01","2012-02-01","2012-03-01","2012-04-01",
>>"2012-05-01","2012-06-01","2012-01-01","2012-02-01",
>>"2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>>0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,
>>158356,162157,166226,33.47,34.48,35.24,38.42,35.33,
>>34.43,433,433,433,433,433,433,2005,2005,2005,2005,
>>2005,2005,3939,3939,3939,3939,3939,3939),nrow=18,
>>ncol=3,byrow=FALSE,dimnames=list(c(1,2,3,4,5,6,7,8,9,
>>10,11,12,13,14,15,16,17,18),c("date","value","code"
>>
>> dados2 <- split(dados, dados$code)
>> dados2
>>
>> library(XLConnect)
>>
>> wb <- loadWorkbook("Teste.xlsx", create = TRUE)
>> createSheet(wb, name = "Teste1")
>> writeWorksheet(wb, dados2, sheet = "Teste1")
>> saveWorkbook(wb)
>>
>> With this code I only get the "433" series. How could I
>> fix my code? How could I include the other series?
>>
>> Many thanks in advance,
>> Henrique Andrade
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Henrique Andrade

__
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] Saving Splitted Series to Excel via XLConnect

2012-08-08 Thread Henrique Andrade
Dear Arun,

Thanks a lot for your help, but I really need to save the splitted
data in a Excel file (xlsx or xls). This is because I will need to
make links between different Excel workbooks.

Best regards,
Henrique Andrade

Enviado via iPhone

Em 08/08/2012, às 17:25, arun  escreveu:

> Hi,
>
> I think saving it as .csv file will be much easier.  I am getting all the 
> series in the wide format.
>
> write.csv(dados2,"dados2.csv")
>
>
> X2005.date X2005.value X2005.code X3939.date X3939.value X3939.code X433.date 
> X433.value X433.code
> 7 2012-01-01 152136 2005 2012-01-01 33.47 3939 2012-01-01 0.56 433
> 8 2012-02-01 153081 2005 2012-02-01 34.48 3939 2012-02-01 0.45 433
> 9 2012-03-01 155872 2005 2012-03-01 35.24 3939 2012-03-01 0.21 433
> 10 2012-04-01 158356 2005 2012-04-01 38.42 3939 2012-04-01 0.64 433
> 11 2012-05-01 162157 2005 2012-05-01 35.33 3939 2012-05-01 0.36 433
> 12 2012-06-01 166226 2005 2012-06-01 34.43 3939 2012-06-01 0.08 433
>
> A.K.
>
>
>
> - Original Message -
> From: Henrique Andrade 
> To: R Discussion List 
> Cc:
> Sent: Wednesday, August 8, 2012 4:10 PM
> Subject: [R] Saving Splitted Series to Excel via XLConnect
>
> Dear R Discussion List,
>
> I would like to save my data as a xlsx file. But at first
> I need to split it and then save each series into a Excel
> column. Please take a look at the following code:
>
> dados <- data.frame(matrix(c("2012-01-01","2012-02-01",
>   "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>   "2012-01-01","2012-02-01","2012-03-01","2012-04-01",
>   "2012-05-01","2012-06-01","2012-01-01","2012-02-01",
>   "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>   0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,
>   158356,162157,166226,33.47,34.48,35.24,38.42,35.33,
>   34.43,433,433,433,433,433,433,2005,2005,2005,2005,
>   2005,2005,3939,3939,3939,3939,3939,3939),nrow=18,
>   ncol=3,byrow=FALSE,dimnames=list(c(1,2,3,4,5,6,7,8,9,
>   10,11,12,13,14,15,16,17,18),c("date","value","code"
>
> dados2 <- split(dados, dados$code)
> dados2
>
> library(XLConnect)
>
> wb <- loadWorkbook("Teste.xlsx", create = TRUE)
> createSheet(wb, name = "Teste1")
> writeWorksheet(wb, dados2, sheet = "Teste1")
> saveWorkbook(wb)
>
> With this code I only get the "433" series. How could I
> fix my code? How could I include the other series?
>
> Many thanks in advance,
> Henrique Andrade
>
> __
> 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] Saving Splitted Series to Excel via XLConnect

2012-08-08 Thread Henrique Andrade
Dear R Discussion List,

I would like to save my data as a xlsx file. But at first
I need to split it and then save each series into a Excel
column. Please take a look at the following code:

dados <- data.frame(matrix(c("2012-01-01","2012-02-01",
  "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
  "2012-01-01","2012-02-01","2012-03-01","2012-04-01",
  "2012-05-01","2012-06-01","2012-01-01","2012-02-01",
  "2012-03-01","2012-04-01","2012-05-01","2012-06-01",
  0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,
  158356,162157,166226,33.47,34.48,35.24,38.42,35.33,
  34.43,433,433,433,433,433,433,2005,2005,2005,2005,
  2005,2005,3939,3939,3939,3939,3939,3939),nrow=18,
  ncol=3,byrow=FALSE,dimnames=list(c(1,2,3,4,5,6,7,8,9,
  10,11,12,13,14,15,16,17,18),c("date","value","code"

dados2 <- split(dados, dados$code)
dados2

library(XLConnect)

wb <- loadWorkbook("Teste.xlsx", create = TRUE)
createSheet(wb, name = "Teste1")
writeWorksheet(wb, dados2, sheet = "Teste1")
saveWorkbook(wb)

With this code I only get the "433" series. How could I
fix my code? How could I include the other series?

Many thanks in advance,
Henrique Andrade

__
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] Splitting Data Into Different Series

2012-08-06 Thread Henrique Andrade
Dear Rui and Arun,

Thanks a lot for your help. I will test all the proposed solutions ;-)

Best regards,
Henrique Andrade

2012/8/6 Rui Barradas :
> Hello,
>
> Try the following.
>
> split(data.frame(dados), dados[, "code"])
>
> Also, it's better to have data like 'dados' in a data.frame, like this you
> would have dates of class Date, and numbers of classes numeric or integer:
>
>
> dados2 <- data.frame(dados)
> dados2$date <- as.Date(dados2$date)
> dados2$value <- as.numeric(dados2$value)
> dados2$code <- as.integer(dados2$code)
>
> #See the STRucture
> str(dados2)
>
> The code above would be simplified to split(dados2, dados2$code)
>
> And it's also better to keep the result in a list, they are all in one place
> and you can access the components as
>
> result[[ "433" ]]  # etc.
>
> Hope this helps
>
> Rui Barradas
>
> Em 06-08-2012 18:06, Henrique Andrade escreveu:
>>
>> Dear R Community,
>>
>> I'm trying to write a loop to split my data into different series. I
>> need to make a
>> new matrix (or series) according to the series code.
>>
>> For instance, every time the "code" column assumes the value "433" I need
>> to
>> save "date", "value", and "code" into the "dados433" matrix.
>>
>> Please take a look at the following example:
>>
>> dados <-
>> matrix(c("2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>>
>>
>> "2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>>
>>
>> "2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01",
>>
>> 0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,158356,162157,166226,
>>
>>
>> 33.47,34.48,35.24,38.42,35.33,34.43,433,433,433,433,433,433,2005,2005,2005,
>>  2005,2005,2005,3939,3939,3939,3939,3939,3939),
>> nrow=18, ncol=3, byrow=FALSE,
>>
>> dimnames=list(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18),
>>  c("date", "value", "code")))
>>
>> dados433 <- matrix(data = NA, nrow = 6, ncol = 3, byrow= FALSE)
>> dados2005 <- matrix(data = NA, nrow = 6, ncol = 3, byrow= FALSE)
>> dados3939 <- matrix(data = NA, nrow = 6, ncol = 3, byrow= FALSE)
>>
>> for(i in seq(along=dados[,3])) {
>>  if(dados[i,3] == 433) {dados433[i,1:3] <- dados[i,1:3]}
>> }
>>
>> for(i in seq(along=dados[,3])) {
>>  if(dados[i,3] == 2005) {dados2005[i,1:3] <- dados[i,1:3]}
>> }
>>
>> for(i in seq(along=dados[,3])) {
>>  if(dados[i,3] == 3939) {dados3939[i,1:3] <- dados[i,1:3]}
>> }
>>
>> Best regards,
>> Henrique Andrade
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Henrique Andrade

__
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] Splitting Data Into Different Series

2012-08-06 Thread Henrique Andrade
Dear R Community,

I'm trying to write a loop to split my data into different series. I
need to make a
new matrix (or series) according to the series code.

For instance, every time the "code" column assumes the value "433" I need to
save "date", "value", and "code" into the "dados433" matrix.

Please take a look at the following example:

dados <- 
matrix(c("2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01",

"2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01",

"2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01",

0.56,0.45,0.21,0.64,0.36,0.08,152136,153081,155872,158356,162157,166226,

33.47,34.48,35.24,38.42,35.33,34.43,433,433,433,433,433,433,2005,2005,2005,
2005,2005,2005,3939,3939,3939,3939,3939,3939),
nrow=18, ncol=3, byrow=FALSE,

dimnames=list(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18),
c("date", "value", "code")))

dados433 <- matrix(data = NA, nrow = 6, ncol = 3, byrow= FALSE)
dados2005 <- matrix(data = NA, nrow = 6, ncol = 3, byrow= FALSE)
dados3939 <- matrix(data = NA, nrow = 6, ncol = 3, byrow= FALSE)

for(i in seq(along=dados[,3])) {
if(dados[i,3] == 433) {dados433[i,1:3] <- dados[i,1:3]}
}

for(i in seq(along=dados[,3])) {
if(dados[i,3] == 2005) {dados2005[i,1:3] <- dados[i,1:3]}
}

for(i in seq(along=dados[,3])) {
if(dados[i,3] == 3939) {dados3939[i,1:3] <- dados[i,1:3]}
}

Best regards,
Henrique Andrade

__
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] grep and XML

2012-04-16 Thread Henrique Dallazuanna
Try this:

library(rjson)
j <- fromJSON(file =
'https://raw.github.com/currencybot/open-exchange-rates/master/latest.json')
j$rates$USD

On Mon, Apr 16, 2012 at 6:03 PM, Simon Kiss  wrote:
> Hi all:
> I struggle a lot scraping web data. I still haven't got a handle on the XML 
> package.
> I'd like to get particular exchange rates from this table:
> https://raw.github.com/currencybot/open-exchange-rates/master/latest.json
> This is the code that I'm working with:
> library(RCurl)
> library(XML)
>
> txt<-getURL("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json";)
> txt<-htmlParse(txt, asText=TRUE)
> txt<-  getNodeSet(txt, '//p')
> So, I can get the node, properly but then, if I try soething like this:
> grep(c('USD'), txt)
>
> I get:
> integer(0)
>
> Can anyone suggest a way forward?
> Yours, Simon KIss
>
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to convert seconds to 12 hour time format

2012-04-09 Thread Henrique Dallazuanna
Try this:

Sys.setlocale(category = "LC_TIME", locale = "US")
format(as.POSIXct('0001-01-01 00:00:00') + x, "%I:%M:%S %p")


On Mon, Apr 9, 2012 at 9:38 PM, cassie jones  wrote:
>
> Hello everyone,
>
> I am wondering if there is any routine in R which can convert time given in
> 'seconds' unit to the 12 hour time format. For example, suppose the data
> set looks like
>
> x=c(36885,84000,20)  #x in seconds
>
> I want to get the output as
>
> [1] " 11:14:45 AM"
> [2] " 11:20:00 PM"
> [3] "12:20:00 AM"
>
> Does anyone have any idea? Thanks in advance.
>
>
> Cassie
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Help Using Spreadsheets

2012-04-06 Thread Pedro Henrique

Hi, Petr,
Thanks for answering.
Yes, I do read the file with the "read.xls" command but I do not know how to 
read it into an object.
I read the R-into document chapter of objects, but I is still not clear for 
me how to transform this kind of data into an object.


Regards,

Lämarao


- Original Message - 
From: "Petr PIKAL" 

To: "Pedro Henrique" 
Cc: 
Sent: Friday, April 06, 2012 6:27 AM
Subject: Hi: [R] Help Using Spreadsheets


Hi

Hello,

I am a new user of R and I am trying to use the data I am reading from a



spreadsheet.
I installed the xlsReadWrite package and I am able to read data from

this

files, but how can I assign the colums into values?
E.g:
as I read a spreadsheet like this one:


Maybe with read.xls? Did you read it into an object?


A B
1 2
4 9

I manually assign the values:
A<-c(1,4)
B<-c(2,9)


Why? If you read in to an object (e.g. mydata)




to plot it on a graph:
plot(A,B)


plot(mydata$A, mydata$B)




or make histograms:
hist(A)


hist(mydata$A)



But actualy I am using very large colums, does exist any other way to do



it automatically?


Yes. But before that you shall automatically read some introduction
documentation like R-intro)

Regards
Petr



Best Regards,

Lämarăo
   [[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 Using Spreadsheets

2012-04-05 Thread Pedro Henrique
Hello,

I am a new user of R and I am trying to use the data I am reading from a 
spreadsheet.
I installed the xlsReadWrite package and I am able to read data from this 
files, but how can I assign the colums into values?
E.g:
as I read a spreadsheet like this one:
A B
1 2
4 9

I manually assign the values:
A<-c(1,4)
B<-c(2,9)

to plot it on a graph:
plot(A,B)

or make histograms:
hist(A)

But actualy I am using very large colums, does exist any other way to do it 
automatically?

Best Regards,

Lämarão
[[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] R equivalent for SQL query

2012-04-03 Thread Henrique Dallazuanna
Here is another way:

aggregate(.~ A + B, FUN = length, x)


On Tue, Apr 3, 2012 at 3:26 PM, Steven Raemaekers wrote:

> Hi,
>
> I have a query which I would like to translate into R, but I do not know
> how to do it in an easy way.
> Assume a data frame has columns A, B and C:
>
> A   B   C
> 1   1   3
> 1   1   4
> 1   1   5
> 1   2   6
> 1   2   7
> 1   3   8
>
> The query is as follows:
>
> select A, B, count(*)
> from data.frame
> group by A, B
> order by count(*) desc
>
> How do I translate this into R statements in such way that the result is a
> data frame structured as follows:
>
> A   B   count(*)
> 1   1   3
> 1   2   2
> 1   3   1
>
> Thanks,
>
> Steven
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] subtract a list of vectors from a list of data.frames in an elegant way

2012-03-31 Thread Henrique Dallazuanna
Try this:

mapply('[', DBquery, mapply(setdiff, lapply(DBquery, names), lookup))

On Sat, Mar 31, 2012 at 5:50 PM, Eric Fail  wrote:
> a working solution to the problem,
>
>  a <- DBquery[names(lookup)]
>
> mother.of.lookup <- list()
> for(string in names(a)) {
>   a[[string]] <- names(a[[string]])
>   mother.of.lookup[[string]] <- setdiff(a[[string]], lookup[[string]])
> }
>
> identical(mother.of.lookup, result)
>
> It might not be the most elegant solution, but it works.
>
> Best,
> Eric
>
> On Thu, Mar 29, 2012 at 4:07 AM, Jim Holtman  wrote:
>>
>> ?setdiff
>>
>> Sent from my iPad
>>
>> On Mar 29, 2012, at 4:28, "Eric Fail"  wrote:
>>
>> > Dear R experts,
>> >
>> > I've realized that it might not be possible to define a negative SELCET 
>> > statement in a SQL call so now I'm looking for the smoothest way to 
>> > generate a list of what I would like from my large database by first 
>> > pulling all the names with a query like this "SELECT top 1 * FROM 
>> > your_table" (thank you Bart Joosen for the idea) and then subtract the 
>> > variables I am not allow to pull manually ending up with a 'positive' 
>> > definition of what I want, something I can use in a SQL SELCT statement 
>> > (see my email on this list from yesterday for more on that).
>> >
>> > When I query the database for the variable names I get something similar 
>> > to 'DBquery' in my working example below, but considerable longer with 
>> > over 2400 hundred variables. As I only need to remove two or three 
>> > variables I would like to define a lookup table (like the list 'lookup' in 
>> > my example) and subtract that from my data base query. Now to my question. 
>> > Is there a way I can subtract one list from another? Like setoff or alike?
>> >
>> > I would like to end up with a list like the one shown in my example called 
>> > 'result.' In short, I would like to subtract 'lookup' from 'DBquery' and 
>> > end up with 'result,' please note that 'result' is a list fo vecktors and 
>> > not a list of dataframes. In my real life example DBquery is considerable 
>> > longer so defining that by hand would make a really really long syntax.
>> >
>> > Hope someone know some smart function that I can use to solve my problem 
>> > in an elegant way.
>> >
>> > Thanks for reading.
>> >
>> > Erick
>> >
>> > ## begin R code ##
>> >
>> > DBquery     <- list(tableA=data.frame(id = numeric(0), atwin = numeric(0), 
>> > atrout = numeric(0)),
>> >                    tableB=data.frame(id = numeric(0), mq   = numeric(0), z 
>> > = numeric(0), m = numeric(0)),
>> >                    tableC=data.frame(V1 = numeric(0), mfn   = numeric(0), 
>> > iiff = numeric(0)),
>> >                    tableD=data.frame(id    = numeric(0), msf   = 
>> > numeric(0), oom  = numeric(0)))
>> >
>> > lookup     <- list(tableA=   c('atwin', 'atrout'),
>> >                   tableB=    c('m', 'z'),
>> >                   tableC=    'ALL')
>> >
>> > ### ...
>> >
>> > result     <- list(tableA= c('id'),
>> >                    tableB= c('id', 'mq'),
>> >                    tableC= c('V1', 'mfn', 'iiff'))
>> >
>> > __
>> > 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.



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] read.csv and field containing single quotes

2012-03-26 Thread Henrique Dallazuanna
Benilton,

Try this:

read.table(textConnection(gsub('","', "','", gsub('^\"|\"$', "'",
readLines('../teste.csv', sep = ',', quote = "'", header = TRUE)

On Mon, Mar 26, 2012 at 8:09 PM, Benilton Carvalho
 wrote:
> I need to read in csv files, created by 3rd party, with fields
> containing single quotes (as shown below).
>
> "header1","header2","header3","header4"
> "field1r1","field2r1","field3r1","field4r1"
> "field1r2","field2r2","field3r2PartA), field3r2PartB Very" Long","field4r2"
> "field1r3","field2r3","field3r3","field4r3"
>
>
> read.csv(filename, quote="\"'", header=TRUE) won't read the file
> represented above, unless the 3rd line has Very""  (double quotes)
> instead of Very" (single quotes)... and this is documented (scan() man
> page).
>
> Assuming that the creation of such csv files is something I'm not in a
> position to interfere with, are there (preferably, "all in R")
> suggestions on how to handle such task?
>
> For the moment, I'm using my poor man's solution (below), but any
> tricks that would simplify this task would be great.
>
> Thank you very much,
>
> benilton
>
>
> parser <- function(fname, header=TRUE, stringsAsFactors=FALSE){
>    txt <- readLines(fname)
>    txt <- gsub("^\"|\"$", "", txt)
>    txt <- strsplit(txt, "\",\"")
>    txt <- do.call(rbind, lapply(txt, function(x) gsub("\"", "\"\"", x)))
>    if (header){
>        nms <- txt[1,]
>        txt <- txt[-1,]
>    }
>    txt <- as.data.frame(txt, stringsAsFactors=stringsAsFactors)
>    if (header) names(txt) <- nms
>    txt
> }
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] string substitution for argument in function

2012-03-25 Thread Henrique Dallazuanna
try this:

`names<-`(rep(2, 3), a)


On Sun, Mar 25, 2012 at 6:22 PM, Pedro Martinez
 wrote:
>
> hello,
> I want to iterate through a list of names and use each element as an
> argument in a function. For instance:
>
> > a = c('one','two','three')
> > data= c()
> > for(elem in a){data=cbind(elem = 2,data)}
> > data
>     elem elem elem
> [1,]    2    2    2
>
> instead I want 'elem' to be substituted by the string in the list. Doing
> it by hand would be:
> > data = cbind('one'=2,data)
> > data = cbind('two'=2,data)
> > data = cbind('three'=2,data)
> > data
>     'one' 'two' 'three'
> [1,]    2    2    2
>
> I guess that the clue would be in sub(),gsub(), paste() or similar but I
> didnt get it to work.
>
> I am comming from python were we woudl do something like:
> > a = ['one','two','three']
> > data = {}
>
> > for elem in a:
> >       data[elem] = 2
>
> > data
> {'three': 2, 'two': 2, 'one': 2}
>
> Thanks, Pedro
>
>
> -
> Prof. Dr. P. Martinez Arbizu
> DZMB-Forschungsinstitut Senckenberg
>
> Suedstrand 44
> D-26382 Wilhelmshaven
> Germany
>
> Tel: +49 (0)4421 9475-100
> Fax: +49 (0)4421 9475-111
>
> Email: pmarti...@senckenberg.de
>
> Senckenberg Gesellschaft für Naturforschung
> Rechtsfähiger Verein gemäß § 22 BGB
> Senckenberganlage 25
> 60325 Frankfurt
> Direktorium: Prof. Dr. Dr. h.c. Volker Mosbrugger, Prof. Dr. Michael
> Türkay, Dr. Johannes Heilmann, Prof. Dr. Pedro Martinez Arbizu, Prof.
> Dr. Georg Zizka, Prof. Dr. Uwe Fritz
> Vorsitzender des Präsidiums: Dietmar Schmid
> Aufsichtsbehörde: Magistrat der Stadt Frankfurt am Main (Ordnungsamt)
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] editing import data, strings

2012-02-17 Thread Henrique Dallazuanna
Try this:

setClass("myClass")
setAs("character", "myClass", function(from)as.numeric(gsub(",", "", from)))

d <- read.table("clipboard", sep = ",", check.names = FALSE, quote = '"',
header = TRUE, fill = TRUE, colClasses = c('character', rep('myClass',
232)))

On Fri, Feb 17, 2012 at 3:24 PM, gaja  wrote:

> Regards.
>
> I'm a beginner in programing, so I have a basic question for you.
> If someone could help me please..
>
> I want to create a function, which will be able to export files from excel.
> I tried with
> a <- read.csv(file, sep =",", as.is = TRUE, row.names = 1, header = TRUE),
>
> .. but instead of numbers, it gives me strings for example: "299,311".
>
> I can handle this string for example:
> b <- "299,311"
> as.numeric(gsub(",", "", b))
> 299311
>
> Now, I´m interested how to inport it from that file,.
>
> I tried with
> a <- read.csv(file, sep =",", as.is = TRUE, row.names = 1, header = TRUE)
> a <- gsub(",", "", a)
> a <- as.numeric(a)
>
> But it doesn't work.
> I used search engine on forum, but didn't find any function that I could
> help with.
>
> I would be very gratefull if someone could help me.
>
> Gaja
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4397899.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Reading in csv with footer

2012-02-12 Thread Henrique Dallazuanna
This works for me:

Lines <- "label_1, label_2, label_3
1,2,3
3,2,4
2,3,4
Total Rows: 3"

d <- head(read.csv(textConnection(Lines)), -1)
closeAllConnections()

On Sun, Feb 12, 2012 at 10:05 PM, Noah Silverman wrote:

> Hi,
>
> I have a CSV file that is formatted well, except that the last line is a
> "summary" not is CSV format.
>
> Toy example:
>
> label_1, label_2, label_3
> 1,2,3
> 3,2,4
> 2,3,4
> Total Rows: 3
>
>
> When I try to import this into R with:  d <- read.table("foo.csv",
> header=T, sep=",")
> It fails to import properly because of the last line.
>
> Currently, I have a shell script that strips the last line from the file,
> then it imports to R cleanly.  I don't like this extra layer of processing.
>
> Is there a way to import something like this cleanly in R.
>
> Thanks!
>
> --
> Noah
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] [R-sig-DB] Reading data from a worksheet on the Internet

2012-02-12 Thread Henrique Dallazuanna
Try the readHTMLTable function in package XML:

sheet2 <- readHTMLTable("
http://www.mar.mil.br/dhn/chm/meteo/prev/dados/pnboia/sc1201_arquivos/sheet002.htm";,
skip.rows = 2)

head(sheet2[[1]])

On Sun, Feb 12, 2012 at 4:24 PM, Nilza BARROS  wrote:

> Hi,
>
> I really appreciate your help. I definitively need a reusable program since
> I have been asking to  someone to extract these data from the Internet
> everyday.  That's the reason why I am trying to do a program to do that
> Related to the url I sent, I have just realized that although I had written
>  the one related to only worksheet (PLANILHA2) when I copy it to my browse
> it is showed the link with both worksheets.
>
>
> I am going to read about Rcurl and XML libraries but I hope you can help me
> too.
>
> Thanks in advance
> Nilza Barros
>
>
> On Sun, Feb 12, 2012 at 10:42 AM, CIURANA EUGENE (R)  >wrote:
>
> > **
> >
> > On Sat, 11 Feb 2012 22:49:07 -0200, Nilza BARROS wrote:
> >
> > I have to read data from a worksheet that is available on the Internet. I
> > have been doing this by copying the worksheet from the browser.
> > But I would like to be able to copy the data automatically using the url
> > command.
> >
> > But when using  "url" command the result is the source code, I mean, a
> html
> > code.
> > I see that the data I need is in the source code but before thinking
> about
> > reading the data from the html code I wonder if there is a package or
> > anoher way to extract these data since reading  from the code will demand
> > many work and it can be not so accurate.
> >
> > Below one can see the from where I am trying to export the data:
> >
> > dadoshttp://
> www.mar.mil.br/dhn/chm/meteo/prev/dados/pnboia/sc1201_arquivos/sheet002.htm
> ","r
> > ")
> >
> >
> >
> > Hi Nilza,
> >
> > The URL that you posted points at a document that has another document
> > within it, in a frame.  These files are Excel dumps into HTML.  To view
> the
> > actual data you need the URIs for each data set.  Those appear at the
> > bottom of the listing, under sc1201_arquivos/sheet001.htm and
> sheet002.htm.
> >  Your code must fetch these files, not the one at
> > http://www.mar.mil.br/dhn/chm/meteo/prev/dados/pnboia/sc1202.htm which
> > only "wraps" them.  Most of what you see on the file that you linked
> isn't
> > HTML - it's JavaScript and style information for the data living on the
> two
> > separate HTML documents.
> >
> > You can do this in R using the RCurl and XML libraries, by pulling the
> > specific files for each data source.  If this is a one-time thing, I'd
> > suggest just coding something simple that loads the data for each file.
>  If
> > this is something you'll execute periodically, you'll need a bit more
> code
> > to extract the internal data sheets (e.g. the "planhilas" at the bottom),
> > then extracting the actual data.
> >
> > Let me know if you want this as a one-time thing, or as a reusable
> > program.  If you don't know how to use RCurl and XML to parse HTML I'll
> be
> > happy to help with that too.  I'd just like to know more about the scope
> of
> > your question.
> >
> > Cheers,
> >
> > pr3d
> >
> > --
> > pr3d4t0r at #R, ##java, #awk, #pytonirc.freeenode.net
> >
> >
>
>
> --
> Abraço,
> Nilza Barros
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] String position character replacement

2012-02-08 Thread Henrique Dallazuanna
Try this:

sapply(mapply(replace, x = strsplit(avec, NULL), list = alist, MoreArgs =
list(values = "-")), paste, collapse = "")

On Wed, Feb 8, 2012 at 3:33 PM, Yang, Joy (NIH/NHGRI) [F]
wrote:

> Hi,
>
> Is there a way to efficiently replace specified indices in a string with
> another character? For example, if I had a vector of strings such as
>
> [1] "hellohowareyoudoing"
> [2] "imgoodhowareyou"
> [3] "goodandyou"
> [4] "yesimgoodijusttoldyou"
> [5] "ohyesthatsright"
>
> and had a list of positions that I want to replace with the character "-"
>
> [[1]]
> [1]  3  9
>
> [[2]]
> [1]  3  4
>
> [[3]]
> [1]  4  7
>
> [[4]]
> [1] 5 6 7 8 9
>
> [[5]]
> [1]  2  5  7 12
>
> I would like to get
>
> [1] "he-lohow-reyoudoing"
> [2] "im--odhowareyou"
> [3] "goo-an-you"
> [4] "yesi-ijusttoldyou"
> [5] "o-ye-t-atsr-ght"
>
> Is there an easy way to do this? Or would the easiest way be writing a
> function to take substrings of the original vector and pasting in the
> replacement character?
>
> Thanks in advance!
> Joy
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Webscraping - How to Scrape Out Text Into R As If Copied & Pasted From Webpage?

2011-10-26 Thread Henrique Dallazuanna
Use XPATH query:

web.pg <- htmlTreeParse(file=web.pg, ignoreBlanks=TRUE, useInternalNodes = TRUE)

# Job title
xpathApply(web.pg, "//span[@class='normal']//b", xmlValue)

On Wed, Oct 26, 2011 at 9:36 PM, Moser, Gary  wrote:
> Greetings,
>
>
>
> I am trying to get all of the text from a web page as if I "selected
> all" on the page, pasted into a text file, and then read in the text
> file with read.csv().
>
>
>
> # this is the actual page I'm trying to acquire text from:
>
> web.pg <- readLines("http://www.airweb.org/?page=574";)
>
>
>
> # then parsed in hopes of an easier structure to work with:
>
> web.pg <- htmlTreeParse(file=web.pg, ignoreBlanks=TRUE)
>
>
>
> Now I have a lovely html tree, but don't know the best way to get just
> the text components (job descriptions, job titles, etc...) as they
> appear on the web site. I'd like to do a little text mining and make a
> wordcloud using the text. Can anybody suggest a method to achieve this
> result?
>
>
>
> Thank you,
>
>
>
> Gary R. Moser
>
> Institutional Research Analyst
>
> Heald College
>
> p <- 415.808.1533
>
> f <- 415.808.1598
>
> gary_mo...@heald.edu <mailto:gary_mo...@heald.edu>
>
>
>
>
>
> Disclaimer: This communication may contain Heald College confidential and 
> proprietary data. This message is intended only for the personal and 
> confidential use of the designated recipients named above. If you are not the 
> intended recipient of this message you are hereby notified that any review, 
> dissemination, distribution or copying of this message is strictly 
> prohibited. In addition, if you have received this message in error, please 
> advise the sender by reply email and delete the message.
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] replacing percentage of values in data frame

2011-10-19 Thread Henrique Dallazuanna
Try this:

data$V6[sample(nrow(data), ceiling(length(data$V6) * 0.2))] <- 1

On Wed, Oct 19, 2011 at 9:38 PM, a217  wrote:
> I've been looking for how to change a certain percentage of values in a data
> frame, but I've been struggling to find information in R.
>
> For example:
>
> #example data##
>> data
>      V1    V2    V3  V4 V5  V6 V7
> 1   chr1   500   500 CHH  0 0.5  +
> 2   chr1   550   550 CHH  0 0.0  +
> 3   chr2   700   700 CHH  0 0.0  +
> 4   chr2  1000  1000 CHH  0 0.0  +
> 5   chr3   100   100 CHH  0 0.0  +
> 6   chr4   450   450  CG  0 0.0  +
> 7   chr5   450   450 CHH  0 0.0  +
> 8   chr5 50034 50034 CHG  0 0.0  +
> 9   chr7 50055 50055 CHG  0 0.0  +
> 10 chr10 50063 50063 CHH  0 0.0  +
>
>> dput(data)
> structure(list(V1 = structure(c(1L, 1L, 3L, 3L, 4L, 5L, 6L, 6L,
> 7L, 2L), .Label = c("chr1", "chr10", "chr2", "chr3", "chr4",
> "chr5", "chr7"), class = "factor"), V2 = c(500L, 550L, 700L,
> 1000L, 100L, 450L, 450L, 50034L, 50055L, 50063L), V3 = c(500L,
> 550L, 700L, 1000L, 100L, 450L, 450L, 50034L, 50055L, 50063L),
>    V4 = structure(c(3L, 3L, 3L, 3L, 3L, 1L, 3L, 2L, 2L, 3L), .Label =
> c("CG",
>    "CHG", "CHH"), class = "factor"), V5 = c(0L, 0L, 0L, 0L,
>    0L, 0L, 0L, 0L, 0L, 0L), V6 = c(0.5, 0, 0, 0, 0, 0, 0, 0,
>    0, 0), V7 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>    1L), .Label = "+", class = "factor")), .Names = c("V1", "V2",
> "V3", "V4", "V5", "V6", "V7"), class = "data.frame", row.names = c(NA,
> -10L))
>>
> 
>
> Say for instance, I'd like to change 20% of values in column 6 to '1'
> instead of zero or whatever value may be currently present. How would I
> approach this?
>
> I am working with a large data frame and I need to replace values in one of
> the columns for 10-20% of the entire dataset. I hope what I am trying to
> convey is understandable to you.
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/replacing-percentage-of-values-in-data-frame-tp3920484p3920484.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Bartlett's Test of Sphericity

2011-10-09 Thread Fernando Henrique Ferraz Pereira da Rosa
You could also check this function I implemented awhile back:

http://www.fernandohrosa.com.br/en/P/sphericity-test-for-covariance-matrices-in-r-sphericity-test/

On Fri, Jun 17, 2011 at 4:43 PM, thibault grava wrote:

> Hello Dear R user,
>
> I want to conduct a Principal components analysis and I need to run two
> tests to check whether I can do it or not. I found how to run the KMO
> test, however i cannot find an R fonction for the Bartlett's test of
> sphericity. Does somebody know if it exists?
>
> Thanks for your help!
>
> Thibault
>
>[[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.
>



-- 
"Though this be randomness, yet there is structure in't."
Fernando H Rosa - Statistician
http://www.fernandohrosa.com.br / http://www.feferraz.net - Estatística,
Matemática e Computação
BankReview.com.br  - Escolha melhor seus
serviços financeiros!
AprendaAlemao.net  - Seu ponto de partida para
melhorar seu Alemão!
@fhrosa

[[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] Saving a list as a Matrix

2011-09-03 Thread Henrique Dallazuanna
Try this:

t(sapply(lst1, '[', 1:max(sapply(lst1, length

On Sat, Sep 3, 2011 at 3:37 PM, wizykid  wrote:
> Hi there.
>
> I went through the manual but I couldn't find a solution for my problem.
>
> I have list like this one :
>> lst1
> [[1]]
> [1] 0 1 2 3
>
> [[2]]
> [1] 0 1 5
>
> [[3]]
> [1] 2 3 4
>
> and I want to save it as Matrix in Matlab mat format like :
> 0 1 2 3
> 0 1 5 0
> 2 3 4 0
>
>
> can any body help me ? Appreciate your help and thanks in advance.
>
> Reza
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Saving-a-list-as-a-Matrix-tp3788274p3788274.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to keep the same class?

2011-09-02 Thread Henrique Dallazuanna
Try this:

predict(fit10,testX[1,,drop = FALSE])

On Fri, Sep 2, 2011 at 5:05 PM, Eduardo M. A. M.Mendes
 wrote:
> Hello
>
>
>
> Please see the example below
>
>
>
>> class(testX)
>
> [1] "matrix"
>
>> class(testX[1,])
>
> [1] "numeric"
>
>
>
> Why not matrix?   What am I missing here?   Is there a way to keep the same
> class?
>
>
>
> The reason for the question is that I want to implement a k-step ahead
> prediction for my own routines and R wrecks does not seem to like [1,] as
> shown below.
>
>
>
>> predict(fit10,testX[1,])
> Error in knnregTrain(train = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  :
>  dims of 'test' and 'train differ
>> predict(fit10,testX[1:2,])
> [1] 81.00 76.36
>
>
>
> Many thanks
>
>
>
> Ed
>
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to create data.frames from vectors with duplicates

2011-08-31 Thread Henrique Dallazuanna
Try this:

rowsum(x, y)

On Wed, Aug 31, 2011 at 1:45 PM, zhenjiang xu  wrote:
>
> Hi R users,
>
> suppose I have two vectors,
>  > x=c(1,2,3,4,5)
>  > y=c('a','b','c','a','c')
> How can I get a data.frame like this?
> > xy
>      count
> a     5
> b     2
> c     8
>
> I know a few ways to fulfill the task. However, I have a huge number
> of this kind calculations, so I'd like an efficient solution. Thanks
>
> --
> Best,
> Zhenjiang
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] character vector to text with returns

2011-08-29 Thread Henrique Dallazuanna
Try:

paste(c("a", "b", "c"), collapse = "\n")

On Mon, Aug 29, 2011 at 8:56 PM, Ben qant  wrote:

> Hello,
>
> Does anyone know how to convert this:
> > msg
>  [1] "a"
>  [2] "b"
>  [3] "c"
>
>
> To:
>
> > msg
> "a
>  b
>  c"
>
> In other words, I need to convert a character vector to a single string
> with
> carriage returns for each row.
>
> Functionally, I'm attempting to send an email of a character vector in a
> way
> that is readable in the email body. I can only input one string as the
> message body parameter. I'm using rJython to send the email because I need
> authentication.
>
> Thanks!
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] sum of two lists

2011-08-29 Thread Henrique Dallazuanna
Try this:

as.list(colSums(merge(m, n, all = TRUE), na.rm = TRUE))

On Mon, Aug 29, 2011 at 7:39 PM, zhenjiang xu wrote:

> Hi R users,
>
> Suppose I have two lists and the names of list 'm' are a subset of those of
> 'n', how can I sum the two lists with corresponding elements added together
> to get list 'o'?
>
> > n = list("a"=1,"b"=3,"c"=5)
> > m = list('b'=4)
> > o
> $a
> [1] 1
>
> $b
> [1] 7
>
> $c
> [1] 5
>
> Thanks
>
> --
> Best,
> Zhenjiang
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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 to get the last modified time of a file from R

2011-08-26 Thread Henrique Dallazuanna
Try this:

file.info("your_file")$mtime

On Fri, Aug 26, 2011 at 4:48 PM, alan wu  wrote:
> Hi All,
>
> I want to add the last modified time of the dataset I used in the
> analysis. Any idea about how to get it from R in windows XP system?
>
> Thanks
>
>
> Alan
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] string manipulation

2011-08-25 Thread Henrique Dallazuanna
Try this:

gsub(".*second number ", "", mytext)

On Thu, Aug 25, 2011 at 8:00 PM, Lorenzo Cattarino
 wrote:
> I R-users,
>
> I am trying to find the way to manipulate a character string to select a 4 
> digit number after some specific word/s. Example:
>
> mytext <- "I do not want the first number 1234, but the second number 5678"
>
> Is there any function that allows you to select a certain number of digits 
> (in this case 5678) after a particular word/s (e.g., second number)
>
> Thank you for your help
>
> Lorenzo
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Help: find the index of the minimum of entries

2011-08-24 Thread Henrique Dallazuanna
Try which.min(a)

On Wed, Aug 24, 2011 at 1:03 PM, Chee Chen  wrote:
> Dear All,
> I would like to ask a question on how to find the index of the minimum of 
> entries of a numeric vector, without using loops or user defined functions.
> Suppose we have a vector:
> a <- c(3,1,2)
> then,
> min(a) = 1
> and its index is 2.
>
> Target:  how to get the index of this minimum? How to get the indices  if 
> multiple entries assume this same minimum?
>
> Thank you,
> Chee
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] subsetting a list of matrices

2011-08-23 Thread Henrique Dallazuanna
Try this:

subset(as.data.frame(do.call(rbind, lapply(l, "[", , 1))), row3 == "Message 1")

On Tue, Aug 23, 2011 at 1:28 PM, Lara Poplarski  wrote:
> Hi all,
>
> I have an object that looks (roughly) like the following:
>
> l <- list(a = matrix(rnorm(9), 3), b = matrix(rnorm(9), 3), c =
> matrix(rnorm(9), 3))
>
> l$a[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
> l$b[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
> l$c[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
>
> rownames(l$a) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
> rownames(l$b) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
> rownames(l$c) <- rownames(c(1:3), do.NULL = FALSE, prefix = "row")
>
> colnames(l$a) <- c("V1", "V2", "V3")
> colnames(l$b) <- c("V1", "V2", "V3")
> colnames(l$c) <- c("V1", "V2", "V3")
>
> I want to extract values (row1, V1) for the three sublists a, b, c,
> but only for those cases in which row3 == "Message 1". Could someone
> suggest how to proceed?
>
> Many thanks in advance,
> Lara
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] test if vector contains elements of another vector (disregarding the position)

2011-08-22 Thread Henrique Dallazuanna
Try this:

i %in% j * 1

On Mon, Aug 22, 2011 at 12:51 PM, Martin Batholdy
 wrote:
> Hi,
>
>
> I have the following problem:
>
>
> I have two vectors:
>
> i <- c('a','c','g','h','b','d','f','k','l','e','i')
>
> j <- c('a', 'b', 'c')
>
>
>
> now I would like to generate a vector with the length of i that
> has zeros where i[x] != any element of j
> and 1 where i[x] == any element of j.
>
> So for the example above the vector would look like this:
>
> c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0)
>
>
>
> can someone help me on this?
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Henrique Dallazuanna
See setGraphicsEventHandlers function.

On Sun, Aug 21, 2011 at 10:04 AM, Eran Eidinger  wrote:
> Thank you Uwe,
>
> That solves the second question.
> Still looking for some solution to zooming in and out dynamically.
>
> Eran.
> 2011/8/21 Uwe Ligges 
>
>>
>>
>> On 21.08.2011 10:17, Eran Eidinger wrote:
>>
>>> Hello all,
>>>
>>> I need to zoom in and out and "travel"(pan) inside a plot, like you can do
>>> on a Matlab plot.
>>>
>>> If possible, I would also like the option to use the mouse to set a marker
>>> on the graph and get the (x,y) data for it, again, like in Matlab.
>>>
>>
>>
>> Don't know about that feature in Matlab, but see ?locator and ?identify for
>> regular R graphics.
>>
>> Uwe Ligges
>>
>>
>>  Is this possible in R with the regular packages, or do you maybe know a
>>> different package that will allow this?
>>>
>>> Eran.
>>> *
>>>
>>>
>>> *
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> __**
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>
>
> --
> *
> Eran Eidinger | Taykey Ltd | +972-54-5908077 | www.taykey.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] splitting sample names

2011-08-18 Thread Henrique Dallazuanna
Try this:

transform(xx, Time = gsub(".*_", "", xx$Sample))

On Thu, Aug 18, 2011 at 6:43 PM, 1Rnwb  wrote:
> I have a data frame like this
> xx<-data.frame(cbind(Sample=c('Ctrl_6h','1+0_6h','1+200_6h','1+5k_6h','Ctrl_5K_6h','ConA_6h'),
>                 IFIT1=c(24,25,24.7,24.5,24.2,24.8)))
>
> grep('[[:digit:]]h',xx$Sample)
>
> yy<-xx$Sample
>
> strsplit(yy,"_")
>
> I have to extract the time information separated by '_' in the sample names,
> i tried grep and strsplit, it looks that i am not providing some information
> correctly. I would appreciate if someone can point me to the correct way.
> Thanks
> Sharad
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/splitting-sample-names-tp3753712p3753712.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] join columns

2011-08-10 Thread Henrique Dallazuanna
Try this:

merge(q1, q2, all = TRUE)

On Wed, Aug 10, 2011 at 12:04 PM, Anthony Ching Ho Ng
 wrote:
> Dear R-help,
>
> I wonder if you could give me some suggestions in how to do a union
> join of two data frames as follow:
> -> union join the common column, and insert a 0 if one is missing.
>
> I made a function to perform the following, and I know it may not that
> quite welly written, but it works.
>
> Any suggestions are welcome, many thanks.
>
> Anthony
>
>> q1 = data.frame(a=1,b=2,c=3,row.names="q1")
>     a b c
> q1 1 2 3
>
>> q2 = data.frame(d=4,b=1,a=4, row.names="q2")
>     d b a
> q2 4 1 4
>
> ->  myJoinColumns(q1,q2)
>     a b c d
> q1 1 2 3 0
> q2 4 1 0 4
>
>
> myJoinColumns <- function(q1,q2){
>  allNames = sort(union(colnames(q1),colnames(q2)))
>  for (i in 1:length(allNames)){
>    t1 = which(colnames(q1) == allNames[i])
>    t2 = which(colnames(q2) == allNames[i])
>
>    if (length(t1) == 1){
>      sec1 = q1[,t1]
>    } else {
>      sec1 = 0
>    }
>
>    if (length(t2) == 1){
>      sec2 = q2[,t2]
>    } else {
>      sec2 = 0
>    }
>
>    if (i == 1){
>      qTable = matrix(c(sec1,sec2))
>    }else{
>      qTable = cbind(qTable,c(sec1,sec2))
>    }
>  }
>  colnames(qTable) = allNames
>  rownames(qTable) = c("q1","q2")
>  qTable
> }
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Loading List data into R with scan()

2011-06-23 Thread Henrique Dallazuanna
Try this:

 sapply(lapply(strsplit(l, ":"), strsplit, ","),
function(x)structure(lapply(x[2], as.numeric), .Names = x[1]))

On Thu, Jun 23, 2011 at 11:39 AM, Michael Pearmain
 wrote:
> Hi All,
>
> I've been given a data file of the form:
> 1: 3,4,5,6
> 2:1,2,3
> 43: 5,7,8,9,5
>
> and i want to read this data in as a list to create the form:
> (guessing final look)
> my.list
> [[1]]
> [1] 3 4 5 6
>
> [[2]]
> [1] 1 2 3
>
> [[43]]
> [1] 5 7 8 9 5
>
> I can get to a stage using scan:
> scan("my.data", what = character(0), quiet = TRUE)
> to load
> [1] "1: 3,4,5,6"
> [2] "2:1,2,3"
> [3] "43: 5,7,8,9,5"
>
> but im not sure on how next to proceed to arrange this into a list form, can
> anyone offer some advise?
>
> Thanks in advance
>
> Mike
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Loading List data into R with scan()

2011-06-23 Thread Henrique Dallazuanna
l <- readLines(textConnection("1: 3,4,5,6
2:1,2,3
43: 5,7,8,9,5"))

On Thu, Jun 23, 2011 at 12:28 PM, Henrique Dallazuanna  wrote:
> Try this:
>
>  sapply(lapply(strsplit(l, ":"), strsplit, ","),
> function(x)structure(lapply(x[2], as.numeric), .Names = x[1]))
>
> On Thu, Jun 23, 2011 at 11:39 AM, Michael Pearmain
>  wrote:
>> Hi All,
>>
>> I've been given a data file of the form:
>> 1: 3,4,5,6
>> 2:1,2,3
>> 43: 5,7,8,9,5
>>
>> and i want to read this data in as a list to create the form:
>> (guessing final look)
>> my.list
>> [[1]]
>> [1] 3 4 5 6
>>
>> [[2]]
>> [1] 1 2 3
>>
>> [[43]]
>> [1] 5 7 8 9 5
>>
>> I can get to a stage using scan:
>> scan("my.data", what = character(0), quiet = TRUE)
>> to load
>> [1] "1: 3,4,5,6"
>> [2] "2:1,2,3"
>> [3] "43: 5,7,8,9,5"
>>
>> but im not sure on how next to proceed to arrange this into a list form, can
>> anyone offer some advise?
>>
>> Thanks in advance
>>
>> Mike
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] accessing files from subfolders

2011-06-08 Thread Henrique Dallazuanna
Try this:

lapply(dir("myPathDir", recursive = TRUE, pattern = "myFile.txt$",
full.names = TRUE), readLines, warn = FALSE)

On Wed, Jun 8, 2011 at 6:35 PM, J  wrote:
> Hi,
>   There must be an easy way to do this, but I'm not finding it..
>
> I'd just like to know the syntax to move up and down folder levels, without 
> necessarily entering a full file path.  Also, how to construct file and 
> folder paths using variables.
>
> For example 1, if I wanted to print to the screen the contents of a file 
> called myFile.txt using the bash shell, I'd use the following:
>
> cat ../myFile.txt
>
> Also, for example 2, if I want to cd into a folder that contains my files, 
> from within a loop, where the counter serves as one of the folders in the 
> path.
>
> In bash:
>
> for i in {1..5} A B C # A, B, and C are also folder names
> do
> cd ~/${i} # move into (change working directory to?) my folder of interest, 
> which is 1,2,3,4,5,A,B,or C
> cat myFile.txt # print corresponding file of interest to screen
> cd - # move back to the previous folder
> done
>
>
> I wonder if there's an easy corresponding way to accomplish this in R.
>
> Any ideas most welcome!
>
> Jonathan
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] subsetting with condition

2011-06-01 Thread Henrique Dallazuanna
Try this:

subset(x, ave(x$ID, x$Pol., FUN = length) >= 3)

On Wed, Jun 1, 2011 at 8:00 PM, kristina p  wrote:
> Dear R Team,
>
> I am a new R user and I am currently trying to subset my data under a
> special condition. I have went through several pages of the subsetting
> section here on the forum, but I was not able to find an answer.
>
> My data is as follows:
>
>  ID                      NAME       MS     Pol. Party
> 1                           John       x       F
> 2                           Mary       s       S
> 3                           Katie      x       O
> 4                           Sarah      p       L
> 5                           Martin      x      O
> 6                           Angelika   x      F
> 7                            Smith      x      O
> 
>
> I am intested in only those observations, where there are at least three
> members of 1 political party. That is, I need to throw out all cases in the
> example above, except for members of party "O".
>
> Would really appreciate your help.
> K
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/subsetting-with-condition-tp3567193p3567193.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Test for list membership

2011-05-30 Thread Henrique Dallazuanna
Try this:

list(c(1,2,3), c(4,5,6)) %in% list(c(1,2,3))

On Mon, May 30, 2011 at 10:36 AM, Marcin Wlodarczak
 wrote:
>
> Hi,
>
> I need some help with this one: how do I check whether a vector is
> already present in a list of vectors.
>
> I have seen %in% recommended in a similar case but that obviously does
> not work here.
>
> c(1,2,3) %in% list(c(1,2,3), c(4,5,6))
>
> returns
>
> [1] FALSE FALSE FALSE
>
> which makes sense since 1, 2 or 3 are not elements of that list. I don't
> really know how to move from there though.
>
> Best wishes,
> Marcin
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] adding up elements within a list

2011-05-17 Thread Henrique Dallazuanna
Try this:

sapply(intvl.period.myrs, sum)

On Tue, May 17, 2011 at 1:13 PM, Martin Hughes  wrote:
>
>
> Dear R users
>
> I have a list, as follows:
>
>> intvl.period.myrs
>
> $Devonian
> [1] 4.8 4.2 9.5 5.7
>
> $Ordovician
> [1]  7.2  5.1 10.2  1.9
>
> $Silurian
> [1] 4.7 3.0 7.8 2.0 3.3 1.6 2.6 2.7
>
>
> I want to write a loop that will sum up the values in each part, and give me
> a
> vector containing the (in this case 3) summed values
>
> this is what I have so far:
>
>                for (i in 1:length(names(intvl.periods.myrs)) {
>                        my.new.vector<-sum(intvl.periods.myrs[i] }
>
> This does not work and probably for obvious reasons.
>
> Thanks
> Martin
>
>
>
>
>
>
> --
> Martin Hughes
> MPhil/PhD Research in Biology
> Rm 1.07,  4south
> University of Bath
> Department of Biology and Biochemistry
> Claverton
> Bath    BA2 7AY
> Tel: 01225 385 437
> m.hug...@bath.ac.uk
> http://www.bath.ac.uk/bio-sci/biodiversity-lab/hughes.html
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] extract integers from string

2011-05-12 Thread Henrique Dallazuanna
Try this:

library(gsubfn)
strapply(x, "\\d+", as.numeric, simplify = rbind)

On Thu, May 12, 2011 at 3:06 PM, Alon Honig  wrote:
> I have a vector with a long list of sentences that contain integers. I
> would like to extract the integers in a manner such that they are
> separate and manipulatable. for example:
> x[i] <- "sally has 20 dollars in her pocket and 3 marbles"
> x[i+1] <-  "30 days ago john had a 400k house"
>
> all sentences are different and contain a mixture of both integers and
> characters.
>
>  i would like to get a conditional matrix such that:
>
> y[i,j] <- 20    y[i,j+1] <- 3
> y[i+1,j] <- 30 y[i+1,j+1] <- 400
>
> based on some criteria (i.e. order, string length, keyword, etc...)
> the integers are sorted.
>
>
> most of my trouble is with finding the correct way to use gsub() or
> strsplit() such that the strings are integers that can be inputed into
> a matrix.
>
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Pretty printing numbers

2011-05-08 Thread Henrique Dallazuanna
formatC(round(2189.745, 2), big.mark=",",format="f", drop0trailing = TRUE)

On Sun, May 8, 2011 at 9:02 PM, Worik R  wrote:
>> formatC(round(2189.745, 2), big.mark=",",format="f")
> [1] "2,189.7400"
>
> Unfortunately this does not work
>
> Worik
>
> On Mon, May 9, 2011 at 11:45 AM, Peter Langfelder <
> peter.langfel...@gmail.com> wrote:
>
>> On Sun, May 8, 2011 at 4:41 PM, Worik R  wrote:
>> > Friends
>> >
>> > I am trying to format a number to a string so 2189.745 goes to "2,189.35"
>> > and 309283.929 goes to "309,283.93"
>> >
>> > I have tried to use formatC(X, big.mark=",",drop0trailing=FALSE,
>> format="f")
>> > but it does not get the number of decimals correct.  Specifying digits
>> does
>> > not work as that is significant digits.  I could use a switch statement
>> > switching on the size of the number to be formated to set the digits
>> > parameter but that is complex and leaves me insecure that thre may be
>> other
>> > problems I have not uncovered.
>> >
>> > Is there a simple way of using library functions to insert big.marks and
>> get
>> > the number of trailing digits correct?  Perhaps some way of using
>> sprintf?
>> >
>>
>> Try this inserting a round() step before the final printing:
>>
>> x = 309283.929
>>
>> formatC(round(x, 2), big.mark=",",drop0trailing=TRUE, format="f")
>>
>> [1] "309,283.93"
>>
>>
>> HTH,
>>
>> Peter
>>
>>
>> > cheers
>> > 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.
>> >
>>
>>
>>
>> --
>> Sent from my Linux computer. Way better than iPad :)
>>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Regexp question

2011-05-04 Thread Henrique Dallazuanna
Try this:

gsub(",\\s+FROM", " FROM", st)

On Wed, May 4, 2011 at 4:41 PM, johannes rara  wrote:
> I have a string like this
>
> st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname),
> COUNT(salary), FROM Employees"
>
> How can I remove the last comma before the FROM statement?
>
> -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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to pass objects from local() to GlobalEnv

2011-05-01 Thread Henrique Dallazuanna
Try this:

local(x <<- 1)

On Sun, May 1, 2011 at 9:20 PM, xiagao1982  wrote:
> Hi all,
>
> I create some objects in local(), and want to pass them to GlobalEnv. How can 
> I do this? Thanks!
>
>
>
>
> xiagao1982
> 2011-05-02
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Question on list object

2011-04-27 Thread Henrique Dallazuanna
Try this:

sapply(listObj, '[', 1:max(sapply(listObj, length)))

On Wed, Apr 27, 2011 at 2:23 PM, Bogaso Christofer
 wrote:
> Dear all, let say, I have following list object:
>
>
>
> listObj <- vector("list", length = 3)
>
> listObj[[1]] <- rnorm(3)
>
> listObj[[2]] <- rnorm(4)
>
> listObj[[3]] <- rnorm(5)
>
>
>
> Now I want to convert above list into a Matrix. Ofcourse I can do it using
> "Reduce("rbind", listObj)". However as you notice that as elements of that
> list are arbitrary length vectors, I cant use this trick. What I want is to
> have a matrix with 3x5 dimension, where the remaining element of each row
> with be filled with NA, i.e I want :
>
>
>
> rbind(c(listObj[[1]], c(NA, NA)), c(listObj[[2]], c(NA)),listObj[[3]])
>
>
>
> Is there any better way on how I can do that more directly?
>
>
>
> Thanks and 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] matrix

2011-04-26 Thread Henrique Dallazuanna
Try this:

replace(m, m[,ncol(m)] < 0, 0)

On Tue, Apr 26, 2011 at 6:28 PM, Val  wrote:
> Hi all,
>
> Assume I have a matrix
> xv=  [1 0 0 0 0 12,
>      0 1 0 0 0 10,
>  *    0 0 1 0 0 -9,*
>      0 0 0 1 0 20,
>    *  0 0 0 0 1 -5]*
>
> if the last column of "xv"  less than  0 then I want to set zero the entire
> row.
> The desired output looks like the following. In this case row 3 and row 5
> are set zero.
>
>    [ 1 0 0 0 0 12,
>      0 1 0 0 0 10,
>     * 0 0 0 0 0 0,*
>      0 0 0 1 0 20,
>    *  0 0 0 0 0 0*]
>
> I used ifelse command but did not work
>
> Is there another command to do that?
>
> Thanks in advance
> \
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Tell the difference between characters

2011-04-26 Thread Henrique Dallazuanna
Try this:

sapply(apply(sapply(temp, charToRaw), 2, unique), length) == 1

On Tue, Apr 26, 2011 at 3:09 PM, Lisa  wrote:
> Dear all,
>
> I just want to determine if the characters in a character string are the
> same or not. For example,
>
> temp <- c("aa", "aA", "ab")
>
> How do I determine the first one have the two same “a”, and the second and
> third have the different characters? Thanks in advance.
>
> Lisa
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Tell-the-difference-between-characters-tp3476130p3476130.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to extract options for a function call

2011-04-18 Thread Henrique Dallazuanna
Try this:

For optim:
eval(formals(optim)$method)

For dist function:
 eval(body(dist)[[3]][[3]])

On Mon, Apr 18, 2011 at 10:56 AM, fisken  wrote:
> Hi, I'm having some difficulties formulating this question.
>
> But what I want,
> is to extract the options associated with a parameter for a function.
>
> e.g.
> method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN")
> in the optim function.
>
> So I would like to have a vector with
> c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN")
>
>
> Or for instance the 'method' in the dist function can be supplied with
> euclidian,maximum,manhatten, canberra,binary,minkowski.
>
> Is there someway to extract this so I would have a vector with
> c("euclidian","maximum","manhatten", "canberra","binary","minkowski").
>
>
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Extract information from the names of a list within lapply

2011-04-15 Thread Henrique Dallazuanna
Try this:

lapply(mtcars, function(.)names(mtcars)[match.call()[[2]][[3]]])

On Fri, Apr 15, 2011 at 3:14 PM, Jun Shen  wrote:
> Dear list,
>
> I want to loop over a list through lapply and at the same time I want to
> extract some information from the names of the list elements. lapply does
> not seem to carry the names. Is there anyway to access the names of a list
> within lapply? Thanks.
>
> Jun
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] add names to data frame

2011-04-14 Thread Henrique Dallazuanna
The matrix is generated by print.dist function ( getS3method("print", "dist") ).

You could try this:

d <- as.matrix(dist(matrix(rnorm(27), 9), diag = TRUE, upper = TRUE))
colnames(d) <- letters[1:9]



On Wed, Apr 13, 2011 at 1:29 PM, Radhouane Aniba  wrote:
> Hi,
>
> I have a vector V of values I used to create a distance matrix using dist()
> function with diag=TRUE and upper=TRUE parameters.
>
> I would like to assign names in another vector on top of each column instead
> of 1 2 3 4 ...
>
> How can we do that ? is the distance matrix generated a data frame or a
> matrix ?
>
> Regards
> --
> *Radhouane *
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Regrouping data

2011-04-08 Thread Henrique Dallazuanna
Try this:

reshape(rat_dat, direction = 'wide', idvar = 'period', timevar = 'name')


On Fri, Apr 8, 2011 at 4:44 AM, Sandeepa Ramakrishnan <
sandeepa_ramakrish...@yahoo.com> wrote:

>Dear R helpers,
>
> Thanks a lot for your kind help. The xtab function suggested by Mr.
> Henrique Dallazuanna produces following output for me
>
>
> > xtabs(values ~ name + period + cy_date, rat_dat)
> , , cy_date = 31-May-11
>
> period
> name 29-Mar-11 30-Mar-11 31-Mar-11
>A 10.37 10.46 10.42
>B 12.61 12.65 12.62
>C 14.08 14.12 14.10
>D 11.17 11.15 11.11
>
> #
> -
>
> I am extremely sorry for framing my question in a wrong way and the output
> I wanted got scattered in my first mail. I am reframing my query as under.
>
> I have a data.frame
>
> rat_dat = data.frame(name = c("A", "A", "A", "B", "B", "B", "C", "C", "C",
> "D", "D", "D"),
>   period = c("31-Mar-11", "30-Mar-11",
> "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11",  "31-Mar-11",
> "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11"),
> values = c(10.42, 10.46, 10.37, 12.62, 12.65, 12.61, 14.10, 14.12, 14.08,
> 11.11, 11.15, 11.17))
>
> > rat_dat
>nameperiod  values
> 1 A  31-Mar-1110.42
> 2 A  30-Mar-1110.46
> 3 A  29-Mar-1110.37
> 4 B  31-Mar-1112.62
> 5 B  30-Mar-1112.65
> 6 B  29-Mar-1112.61
> 7 C  31-Mar-1114.10
> 8 C  30-Mar-1114.12
> 9 C  29-Mar-1114.08
> 10D 31-Mar-1111.11
> 11D 30-Mar-1111.15
> 12    D 29-Mar-1111.17
>
>
> I need to rearrange this data as new new data.frame
>
> rat_dat_new as
>
> period    A   B   C   D
> 31-Mar-11   10.42 12.62   14.1011.11
> 30-Mar-11   10.46 12.65   14.1211.15
> 29-Mar-11   10.37 12.61   14.0811.17
>
> I once again apologize for mistake on my part.
>
> I tried to the solution suggested by Mr. Henrique Dallazuanna, however I
> was not able to read the output as a data.frame.
>
> Kindly guide
>
>
>
>
>
>
>
>
>
>
>
>
>
> --- On *Thu, 7/4/11, Henrique Dallazuanna * wrote:
>
>
> From: Henrique Dallazuanna 
> Subject: Re: [R] Regrouping data
> To: "Sandeepa Ramakrishnan" 
> Cc: r-help@r-project.org
> Date: Thursday, 7 April, 2011, 6:05 PM
>
>
> Try this:
>
> 1)
> xtabs(values ~ name + period + cy_date, rat_dat)
>
>
> 2)
> as.Date(rat_dat$cy_date, '%d-%b-%y') - as.Date(rat_dat$period, '%d-%b-%y')
>
> On Thu, Apr 7, 2011 at 9:03 AM, Sandeepa Ramakrishnan
>  wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Dear R forum
> >
> > I have just started my venture with R. While I am trying to learn R
> through the tutorials, I think the current problem I need to address to is
> beyond my knowledge about R.
> >
> > I have a dataframe as defined below -
> >
> >
> > rat_dat = data.frame(name = c("A", "A", "A", "B", "B", "B", "C", "C",
> "C", "D", "D", "D"),
> >   period = c("31-Mar-11", "30-Mar-11",
> "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11",  "31-Mar-11",
> "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11"),
> > cy_date = c("31-May-11","31-May-11", "31-May-11", "31-May-11",
> "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11",
> "31-May-11", "31-May-11", "31-May-11"),
> > values = c(10.42, 10.46, 10.37, 12.62, 12.65, 12.61, 14.10, 14.12, 14.08,
> 11.11, 11.15, 11.17))
> >
> >
> >> rat_dat
> >nameperiod   cy_date values
> > 1 A 31-Mar-11 31-May-11  10.42
> > 2 A 30-Mar-11 31-May-11  10.46
> > 3 A 29-Mar-11 31-May-11  10.37
> > 4 B 31-Mar-11 31-May-11  12.62
> > 5 B 30-Mar-1

Re: [R] An extention of outer() ?

2011-04-07 Thread Henrique Dallazuanna
Try this:

aperm(outer(x, y, fn1, y), c(3, 1, 2))[,,2]


On Thu, Apr 7, 2011 at 3:21 PM, Bogaso Christofer
 wrote:
> Dear all, as per my understanding, outer() function is to facilitate
> 2-dimensional function evaluation, like to evaluate f(x,y) for different
> values of x and y. However I have slightly modified version of that, where x
> is a matrix with, say, 5 rows and 2 columns and y is a vector. Let take
> following example:
>
>
>
> fn1 <- function(x1, x2, y) return (x1+x2+y)
>
>
>
> x <- matrix(1:10, nc = 2)
>
> y <- 1:5
>
>
>
> with this input, I want to construct a 5x5 matrix whose (1,1)th element will
> be : fn1(x[1,1], x[1,2], y[1]), (1,2)th element will be : fn1(x[1,1],
> x[1,2], y[2]). (1,5)th element will be : fn1(x[1,1], x[1,2],
> y[5]).similarly (2,1)th element will be : fn1(x[2,1], x[2,2],
> y[1])etc
>
>
>
> If my 'x' object is a vector then I can easily use outer() function
> effectively. However for my present case, I am looking for some ***outer()
> like function*** to get the result effectively. Can somebody help me on how
> can I do that without using any for loop?
>
>
>
> Thanks and 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Regrouping data

2011-04-07 Thread Henrique Dallazuanna
Try this:

1)
xtabs(values ~ name + period + cy_date, rat_dat)


2)
as.Date(rat_dat$cy_date, '%d-%b-%y') - as.Date(rat_dat$period, '%d-%b-%y')

On Thu, Apr 7, 2011 at 9:03 AM, Sandeepa Ramakrishnan
 wrote:
>
>
>
>
>
>
>
>
>
> Dear R forum
>
> I have just started my venture with R. While I am trying to learn R through 
> the tutorials, I think the current problem I need to address to is beyond my 
> knowledge about R.
>
> I have a dataframe as defined below -
>
>
> rat_dat = data.frame(name = c("A", "A", "A", "B", "B", "B", "C", "C", "C", 
> "D", "D", "D"),
>   period = c("31-Mar-11", "30-Mar-11", 
> "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11",  "31-Mar-11", 
> "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11"),
> cy_date = c("31-May-11","31-May-11", "31-May-11", "31-May-11", "31-May-11", 
> "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", 
> "31-May-11"),
> values = c(10.42, 10.46, 10.37, 12.62, 12.65, 12.61, 14.10, 14.12, 14.08, 
> 11.11, 11.15, 11.17))
>
>
>> rat_dat
>    name    period   cy_date values
> 1 A 31-Mar-11 31-May-11  10.42
> 2 A 30-Mar-11 31-May-11  10.46
> 3 A 29-Mar-11 31-May-11  10.37
> 4 B 31-Mar-11 31-May-11  12.62
> 5 B 30-Mar-11 31-May-11  12.65
> 6 B 29-Mar-11 31-May-11  12.61
> 7 C 31-Mar-11 31-May-11  14.10
> 8 C 30-Mar-11 31-May-11  14.12
> 9 C 29-Mar-11 31-May-11  14.08
> 10    D 31-Mar-11 31-May-11  11.11
> 11    D 30-Mar-11 31-May-11  11.15
> 12    D 29-Mar-11 31-May-11  11.17
>
> My actual data is too large. I need to
>
> (1) rearrange this input as
>
>
>
>
>
>
>
>
>
> period
>   cy_date
>   A
>   B
>     C
>     D
>
> 31-Mar-11
>  31-May-11
> 10.42
>   12.62
> 14.10
> 11.11
>
> 30-Mar-11
>  31-May-11
> 10.46
>   12.65
> 14.12
> 11.15
>
> 29-Mar-11
>  31-May-11
> 10.37
>   12.61
> 14.08
> 11.17
>
> (2) Also, I need to find the difference between (rat_dat$cy_date) - 
> (rat_dat$period)
>
> I hope I am able to put forward my requirement properly. If not, please 
> forgive me.
>
> Sandeepa
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Two functions as parametrs of a function.

2011-04-07 Thread Henrique Dallazuanna
Try this:

f2 <- function(n, nsim, fun1, fun2) {
vp <- replicate(nsim, do.call(fun1$name, c(n, fun1$args)),
do.call(fun1$name, c(n, fun1$args)))
vp

}

f2(2, 100, fun1 = list(name = rbeta, args = list(shape1 = 2, shape2 =
2), fun1 = list(name = rbeta, args = list(shape1 = 2, shape2 = 2

On Thu, Apr 7, 2011 at 8:45 AM, Kenneth Roy Cabrera Torres
 wrote:
> Hi R users:
>
> I'm trying to make a function where two of the parameters are
> functions, but I don't know how to put each set of parameters for
> each function.
>
> What am I missing?
>
> I try this code:
>
> f2<-function(n=2,nsim=100,fun1=rnorm,par1=list(),fun2=rnorm,par2=list()){
>    force(fun1)
>    force(fun2)
>    force(n)
>    p1<-unlist(par1)
>    p2<-unlist(par2)
>    force(p1)
>    force(p2)
>    localfun1 <- function() fun1(n, p1)
>    localfun2 <- function() fun2(n, p2)
>    vp<-replicate(nsim,t.test(localfun1(), localfun2())$p.value)
>    return(vp)
> }
>
> f2(fun1=rbeta,par1=list(shape1=2,shape2=2),fun2=rbeta,par2=list(shape1=1,shape2=2))
>
> Thank you for your help.
>
> Kenneth
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Calculated mean value based on another column bin from dataframe.

2011-04-06 Thread Henrique Dallazuanna
Try this:

fil <- sapply(ran, '<', e1 = dat[,1]) & sapply(ran[2:(length(ran) +
1)], '>=', e1 = dat[,1])
mm <- apply(fil, 2, function(idx)mean(dat[idx, 2]))

On Wed, Apr 6, 2011 at 5:48 AM, Fabrice Tourre  wrote:
> Dear list,
>
> I have a dataframe with two column as fellow.
>
>> head(dat)
>       V1      V2
>  0.15624 0.94567
>  0.26039 0.66442
>  0.16629 0.97822
>  0.23474 0.72079
>  0.11037 0.83760
>  0.14969 0.91312
>
> I want to get the column V2 mean value based on the bin of column of
> V1. I write the code as fellow. It works, but I think this is not the
> elegant way. Any suggestions?
>
> dat<-read.table("dat.txt",head=F)
> ran<-seq(0,0.5,0.05)
> mm<-NULL
> for (i in c(1:(length(ran)-1)))
> {
>    fil<- dat[,1] > ran[i] & dat[,1]<=ran[i+1]
>    m<-mean(dat[fil,2])
>    mm<-c(mm,m)
> }
> mm
>
> Here is the first 20 lines of my data.
>
>> dput(head(dat,20))
> structure(list(V1 = c(0.15624, 0.26039, 0.16629, 0.23474, 0.11037,
> 0.14969, 0.16166, 0.09785, 0.36417, 0.08005, 0.29597, 0.14856,
> 0.17307, 0.36718, 0.11621, 0.23281, 0.10415, 0.1025, 0.04238,
> 0.13525), V2 = c(0.94567, 0.66442, 0.97822, 0.72079, 0.8376,
> 0.91312, 0.88463, 0.82432, 0.55582, 0.9429, 0.78956, 0.93424,
> 0.87692, 0.83996, 0.74552, 0.9779, 0.9958, 0.9783, 0.92523, 0.99022
> )), .Names = c("V1", "V2"), row.names = c(NA, 20L), class = "data.frame")
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Help in splitting a list

2011-04-05 Thread Henrique Dallazuanna
Try this:

mapply('[', lapply(mylist, as.data.frame), c(index, lapply(index,
`!`)), SIMPLIFY = FALSE)


On Tue, Apr 5, 2011 at 7:46 AM, Lars Bishop  wrote:
> Dear R users,
>
> Let's say I have a list with components being 'm' matrices (as exemplified
> in the "mylist" object below). Now, I'd like to subset this list based on an
> index vector, which will partition each matrix 'm' in 2 sub-matrices. My
> questions are:
>
> 1. Is there an elegant way to have the results shown in mylist2 for an
> arbitrary number of matrices in mylist?
>
> 2. The column names are 'lost' for mylist2[[2]] and mylist2[[4]] (but not
> for mylist2[[1]] and mylist2[[3]]). Is there a way to keep the column names
> in the results of mylist2?
>
> mylist <- list(matrix(1:9,3,3), matrix(10:18,3,3))
> colnames(mylist[[1]])=c('x1','x2','x3')
> colnames(mylist[[2]])=c('x4','x5','x6')
> index <- list(2)
> index[[1]] <- c(TRUE,FALSE,TRUE)
> index[[2]] <- c(FALSE,TRUE,TRUE)
> mylist2 <- list(as.matrix(mylist[[1]][,index[[1]]]),
>                as.matrix(mylist[[1]][,!index[[1]]]),
>                as.matrix(mylist[[2]][,index[[2]]]),
>                as.matrix(mylist[[2]][,!index[[2]]]))
> Thanks for any help,
> Lars.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] merging 2 frames while keeping all the entries from the "reference" frame

2011-04-04 Thread Henrique Dallazuanna
Try this:

 merge(mydata, cbind(reference, group = rep(unique(mydata$group), each
= nrow(reference))), all = TRUE)

On Mon, Apr 4, 2011 at 2:24 PM, Dimitri Liakhovitski
 wrote:
> To clarify just in case, here is the result I am trying to get:
>
> mydate  group   values
> 12/29/2008      Group1  0.453466522
> 1/5/2009        Group1  NA
> 1/12/2009       Group1  0.416548943
> 1/19/2009       Group1  2.066275155
> 1/26/2009       Group1  2.037729638
> 2/2/2009        Group1  -0.598040483
> 2/9/2009        Group1  1.658999227
> 2/16/2009       Group1  -0.869325211
> 12/29/2008      Group2  NA
> 1/5/2009        Group2  NA
> 1/12/2009       Group2  NA
> 1/19/2009       Group2  0.375284194
> 1/26/2009       Group2  0.706785401
> 2/2/2009        Group2  NA
> 2/9/2009        Group2  2.104937151
> 2/16/2009       Group2  2.880393978
>
>
>
> On Mon, Apr 4, 2011 at 1:09 PM, Dimitri Liakhovitski
>  wrote:
>> Hello!
>> I have my data frame "mydata" (below) and data frame "reference" -
>> that contains all the dates I would like to be present in the final
>> data frame.
>> I am trying to merge them so that the the result data frame contains
>> all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
>> Group2 too). But when I merge it it's not coming out this way. Any
>> hint would be greatly appreciated!
>> Dimitri
>>
>> mydata<-data.frame(mydate=rep(seq(as.Date("2008-12-29"), length = 8,
>> by = "week"),2),
>> group=c(rep("Group1",8),rep("Group2",8)),values=rnorm(16,1,1))
>> (reference);(mydata)
>> set.seed(1234)
>> out<-sample(1:16,5,replace=F)
>> mydata<-mydata[-out,]; dim(mydata)
>> (mydata)
>>
>> # "reference" contains the dates I want to be present in the final data 
>> frame:
>> reference<-data.frame(mydate=seq(as.Date("2008-12-29"), length = 8, by
>> = "week"))
>>
>> # Merging:
>> new.data<-merge(mydata,reference,by="mydate",all.x=T,all.y=T)
>> new.data<-new.data[order(new.data$group,new.data$mydate),]
>> (new.data)
>> # my new.data contains only 7 rows in Group 1 and 4 rows in Group 2
>>
>>
>> --
>> Dimitri Liakhovitski
>> Ninah Consulting
>>
>
>
>
> --
> Dimitri Liakhovitski
> Ninah Consulting
> www.ninah.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] lattice: how to "center" a subtitle?

2011-04-04 Thread Henrique Dallazuanna
Maybe:

xyplot(0 ~ 0, xlab =
bquote(expression(atop(alpha==.(x)*","~beta==.(y), bold(foo) )) ))

On Mon, Apr 4, 2011 at 2:58 PM, David Winsemius  wrote:
>
> On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:
>
>> Dear David,
>>
>> do you know how to get plotmath-like symbols in both rows?
>> I tried s.th. like:
>>
>> lab <- expression(paste(alpha==1, ", ", beta==2, sep=""))
>> xlab <- substitute(expression( atop(lab==lab., bold(foo)) ),
>> list(lab.=lab))
>> xyplot(0 ~ 0, xlab = xlab)
>
> I _did_ have plotmath functions in both rows: But here is your solution:
>
> xyplot(0 ~ 0,  xlab =
>    expression( atop(paste(alpha==1, "   ", beta==2), bold(bla) )) )
>      )
>
> Note that `paste` in plotmath is different than `paste` in regular R. It has
> no `sep` argument. I did try both substitute and bquote on you externally
> expression,  but lattice seems to be doing some non-standard evaluation and
> I never got it to "work". Using what I thought _should_ work, does work with
> `plot`:
>
>> x=1;y=2
>> plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*","~beta==.(y), bold(foo) ) )
> + )
>
> But the same expression throws an error with xyplot:
>> x=1;y=2
>> xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*","~beta==.(y), bold(foo) )
>> )
> + )
> Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = "fill",
>  :
>  could not find function "atop"
>
> --
> David.
>
>
>>
>> Cheers,
>>
>> Marius
>>
>> On 2011-04-04, at 18:59 , David Winsemius wrote:
>>
>>>
>>> On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:
>>>
>>>> Dear David,
>>>>
>>>> I intended to use another x-label. But your suggestion brings me to the
>>>> idea of just using a two-line xlab, so s.th. like
>>>> print(xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the
>>>> human's eye", xlab = "but subtitles are _now_ centered\nbla", scales =
>>>> list(alternating = c(1,1), tck = c(1,0
>>>
>>> And if you wanted different fontface (underline, italic or bold) then you
>>> could use plotmath expressions:
>>>
>>> xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the human's
>>> eye", xlab = expression( atop(but~subtitles2~are~underline(now)~centered,
>>> bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))
>>>
>>> --
>>> David.
>>>
>>>>
>>>> Thanks!
>>>>
>>>> Cheers,
>>>>
>>>> Marius
>>>>
>>>> On 2011-04-04, at 16:47 , David Winsemius wrote:
>>>>
>>>>>
>>>>> On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
>>>>>
>>>>>> Dear expeRts,
>>>>>>
>>>>>> I recently asked for a real "centered" title (see, e.g.,
>>>>>> http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
>>>>>> A nice solution (from Deepayan Sarkar) is to use "xlab.top" instead of
>>>>>> "main":
>>>>>>
>>>>>> library(lattice)
>>>>>> trellis.device("pdf")
>>>>>> print(xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the
>>>>>> human's eye", sub = "but subtitles are not centered", scales =
>>>>>> list(alternating = c(1,1), tck = c(1,0
>>>>>> dev.off()
>>>>>
>>>>> library(lattice)
>>>>> trellis.device("pdf")
>>>>> print(xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the
>>>>> human's eye", xlab = "but subtitles are _now_ centered", scales =
>>>>> list(alternating = c(1,1), tck = c(1,0
>>>>> dev.off()
>>>>>
>>>>>
>>>>> (I realize that those are not really subtitles by a 'lab', but that
>>>>> appears acceptable in your current test case.)
>>>>>
>>>>>>
>>>>>> My question is whether there is something similar for *sub*titles [so
>>>>>> something like "xlab.bottom"]? As you can see from the plot, the subtitle
>>>>>> does not seem to be "centered" for the human's eye. I would like to 
>>>>>> center
>>>>>> it according to the x-axis label.
>>>>>>
>>>>>
>>>>>
>>>>> David Winsemius, MD
>>>>> West Hartford, CT
>>>>>
>>>>
>>>
>>> David Winsemius, MD
>>> West Hartford, CT
>>>
>>
>
> David Winsemius, MD
> West Hartford, CT
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Creating multiple vector/list names-novice

2011-04-04 Thread Henrique Dallazuanna
Try this:

 lapply(2:3, FUN = combn, x = string, paste, collapse = '')

On Mon, Apr 4, 2011 at 11:24 AM, michalseneca  wrote:
> Hi I have very simple issue as I am still new to the group of R
>
> I have basically
>
> vector of names for which i want to create mutliple combinations and then
> place them in different vectors. In some other language I can just place a
> third dimension to separate list (or matrix) but i do not know how to do it
> in R.
>
> My issue is simple I use
> cc<-combn(colnames(DD),2)
>
> I would need to have this as
>
> vector1 or like vector[,,1] :           cc<-combn(colnames(DD),2)
> vector2or like vector[,,2]              cc<-combn(colnames(DD),3)
>
> etc..for up to k combinations
>
> something so then I can use for loop to go through the al of these
> combinations
>
> example:
>
> string<-"a", "b" , "c" ",d"
>
> vector/list(1) ab ac ad bc bd be cd ce de
> vector/list  (2) abc abd abe bcd bce bde cde
>
>
> Can you help me with this.. I know that it is a simple question for this
> thread thank you..
>
> Michal
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3425616.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] function in argument

2011-04-01 Thread Henrique Dallazuanna
Or:

foo<-function (x, xfun = dist) {
match.fun(xfun)(x)
}

On Fri, Apr 1, 2011 at 7:06 PM, array chip  wrote:
> OK, I figured it out, need to add stats::: before dist
>
> foo<-function (x,
>    xfun = stats:::dist)
> {
> xfun(x)
> }
>
>
> John
>
>
> 
>
> To: r-help@r-project.org
> Sent: Fri, April 1, 2011 2:56:06 PM
> Subject: [R] function in argument
>
> Hi, I tried to pass the function dist() as an argument, but got an error
> message. However, almost the same code with mean() as the function to be 
> passed,
>
> it works ok.
>
> foo<-function (x,
>    xfun = dist)
> {
> xfun(x)
> }
>
> foo(matrix(1:100,nrow=5))
> Error in foo(matrix(1:100, nrow = 5)) : could not find function "xfun"
>
>
> foo<-function (x,
>     xfun = mean)
> {
>  xfun(x)
> }
>
> foo(1:10)
> [1] 5.5
>
> what am I missing here?
>
> 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.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] regular expression

2011-04-01 Thread Henrique Dallazuanna
Try this also:

> grep("arg", "arg.symptom", value = TRUE, invert = TRUE)
character(0)
> grep("arg", "liver.symptom", value = TRUE, invert = TRUE)
[1] "liver.symptom"
>


On Fri, Apr 1, 2011 at 1:33 PM, array chip  wrote:
> Great. thank you Bernd! Learned a new thing here.
>
> John
>
>
>
>
> 
> From: Bernd Weiss 
>
> Cc: r-help@r-project.org
> Sent: Thu, March 31, 2011 6:19:25 PM
> Subject: Re: [R] regular expression
>
> Am 31.03.2011 21:06, schrieb array chip:
>> Ok then this code didn't do what I wanted. I want "not including
>> 'arg' before '.symptom'", not individual letters of "arg", but rather
>> as a word.
>>
>> Bill Dunlap suggested using invert=T, it works for single 1
>> condition, but not for 2 conditions here: not including "arg" before
>> ".", but at the same time, does include ".symptom".
>>
>> Any other suggestions would be appreciated
>
> This does work (but I am by no means an expert in regex...). I am using
> 'negative lookbehind'[1] to define an expression like 'arg'.
>
>> grep('(? character(0)
>
>> grep('(? [1] "liver.symptom"
>
> Bernd
>
> [1] http://www.regular-expressions.info/lookaround.html
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] controlling the labels width of a barplot

2011-04-01 Thread Henrique Dallazuanna
Try the cex.names argument in barplot function.

On Fri, Apr 1, 2011 at 10:34 AM, Samuel Le  wrote:
> Dear all,
>
>
>
> I am trying the barplot command but some of the labels are disappearing as 
> there is not enough place on the graph to put them all.
>
> Here is an example of code that doesn't show all the labels:
>
>
>
> barplot(sort(runif(9,0,0.2),decreasing=TRUE),xlim=c(0,20),width=2,names.arg=c("first
>  name","second name","third name","fourth name","fifth name","sixth 
> name","seventh name","eigth name","nineth name"))
>
>
>
> Does someone know a way to control the size of the font in the barplot 
> function, or to give them an inclination angle?
>
>
>
> Many thanks,
>
>
>
> Samuel
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Create Variable names dynamically

2011-03-31 Thread Henrique Dallazuanna
Take a look in ?assign

On Thu, Mar 31, 2011 at 5:42 PM, Noah Silverman  wrote:
> Hi,
>
> I want to create variable names from within my code, but can't find any 
> documentation for this.
>
> An example is probably the best way to illustrate. I am reading data in from 
> a file, doing a bunch of stuff, and want to generate variables with my 
> output.  (I could make a "list of lists" and name all the elements, but I 
> really want separate variables.)
>
>
> #
> #This is just a dummy example, please excuse any shortcuts...
>
> data <- read.table("file", )
> animals <- (data[,animal])
> animals
>> "cat", "dog", "horse"  # Not known what these are before I read the data file
>
> # do a bunch of stuff
>
> mean_cat <- abc
> var_cat <- dfd
> mean_dog <- 123
> var_dog <- 453
> etc..
> ##
>
> I thought of trying to use the paste() function to create the variable name, 
> but that doesn't work:
> for( animal in animals){
>        paste("mean", animal "_") <- 123
> }
>
> Any ideas???
>
> Thanks
>
>
> --
> Noah Silverman
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] transparent grays?

2011-03-31 Thread Henrique Dallazuanna
Try this:

with(trees, symbols(Height, Volume, circles=Girth/24, inches=FALSE, fg
= "gray30",
 bg = sapply(apply(rbind(col2rgb(gray(seq(0,1, l = 10)))/255, alpha =
0.5), 2, as.list), do.call, what = rgb)))


On Thu, Mar 31, 2011 at 2:52 PM, Frostygoat  wrote:
> Is there a grayscale equivalent to alpha levels in rgb?
>
> Example:  I have the following to make red transparent circles overlap
> with previously plotted blue symbols.
>
> symbols(x=sites$long,y=sites$lat,circles=log(sites$prop.nem
> +1),add=T,inches=F,bg=rgb(red=1,green=0,blue=0,
> alpha=0.5),fg=rgb(red=1,green=0,blue=0, alpha=0.5))
>
> I'm having a hard time coming up with a grayscale equivalent.
>
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] read password-protected files

2011-03-31 Thread Henrique Dallazuanna
Using RDCOMCliente:

library(RDCOMClient)
eApp <- COMCreate("Excel.Application")
wk <- eApp$Workbooks()$Open(Filename="your_file",Password="your_password")
tf <- tempfile()
wk$Sheets(1)$SaveAs(tf, 3)

DF <- read.table(sprintf("%s.txt", tf), header = TRUE, sep = "\t")

On Thu, Mar 31, 2011 at 3:33 PM, Shi, Tao  wrote:
> Hi Josh and Prof. Ripley,
>
> Thanks for the quick replies!
>
> Sorry about the HTML email.  It's the default for my yahoo account and forgot 
> to
> switch.
>
> The question was asked by a colleague of mine.  After double-checking, yes, 
> they
> are actually Excel files.  Any idea on how to approach this?
>
> Thanks!
>
> ...Tao
>
>
>
> 
> From: Prof Brian Ripley 
>
> Cc: r-help@r-project.org
> Sent: Thu, March 31, 2011 11:15:35 AM
> Subject: Re: [R] read password-protected files
>
> On Thu, 31 Mar 2011, Shi, Tao wrote:
>
>> Hi list,
>>
>> I have a bunch of .csv files that are password-protected.  I wonder if there
> is
>
> There is nothing in the CSV standard about password protection.  I
> very much doubt that these actually CSV files.  So please follow the
> posting guide [*]
>
>> a way to read them in in R without manually removing the password protection
>>for
>> each file?
>>
> [[elided Yahoo spam]]
>>
>>
>> ...Tao
>>     [[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.
>
> [*] as above: and as you sent HTML you are either full of contempt for
> the helpeRs or failed to do your homework.
>
>
> --
> Brian D. Ripley,                  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] choosing best 'match' for given factor

2011-03-31 Thread Henrique Dallazuanna
Try this:

bestMatch <- function(search, match) {
colnames(match)[pmax(apply(match[,search], 2, which.max) - 1, 1)]
}


On Thu, Mar 31, 2011 at 11:46 AM,   wrote:
> Folks,
>
> I have a 'matching' matrix between variables A, X, L, O:
>
>> a <- structure(c(1, 0.41, 0.58, 0.75, 0.41, 1, 0.6, 0.86, 0.58,
> 0.6, 1, 0.83, 0.75, 0.86, 0.83, 1), .Dim = c(4L, 4L), .Dimnames = list(
>    c("A", "X", "L", "O"), c("A", "X", "L", "O")))
>
>> a
>      A     X     L     O
> A  1.00  0.41  0.58  0.75
> X  0.41  1.00  0.60  0.86
> L  0.58  0.75  1.00  0.83
> O  0.60  0.86  0.83  1.00
>
> And I have a search vector of variables
>
>> v <- c("X", "O")
>
> I want to write a function bestMatch(searchvector, matchMat) such that for 
> each variable in searchvector, I get the variable that it has the highest 
> match to - but searching only among variables to the left of it in the 
> 'matching' matrix, and not matching with any variable in searchvector itself.
>
> So in the above example, although "X" has the highest match (0.86) with "O", 
> I can't choose "O" as it's to the right of X (and also because "O" is in the 
> searchvector v already); I'll have to choose "A".
>
> For "O", I will choose "L", the variable it's best matched with - as it can't 
> match "X" already in the search vector.
>
> My function bestMatch(v, a) will then return c("A", "L")
>
> My matrix a is quite large, and I have a long list of search vectors v, so I 
> need an efficient method.
>
> I wrote this:
>
> bestMatch <- function(searchvector,  matchMat) {
>        sapply(searchvector, function(cc) {
>                             y <- matchMat[!(rownames(matchMat) %in% 
> searchvector) & (index(rownames(matchMat)) < match(cc, rownames(matchMat))), 
> cc, drop = FALSE];
>                             rownames(y)[which.max(y)]
>        })
> }
>
> Any advice?
>
> Thanks,
>
> Murali
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Italicized title from index

2011-03-31 Thread Henrique Dallazuanna
Better:

plot(1, main = bquote("Yield  for " ~ italic(.(as.character(spp))) ~
"in management region" ~ .(region)))

You have a factor, so you need convert it to character


On Thu, Mar 31, 2011 at 8:59 AM, Henrique Dallazuanna  wrote:
> Try this:
>
> plot(1, main = bquote("Yield  for " ~ italic(.(spp)) ~ "in management
> region" ~ .(region)))
>
> On Thu, Mar 31, 2011 at 2:35 AM, Jeremy Newman  wrote:
>> Hi all!
>>
>> I've written a handy script that uses a for loop to allow me to generate a
>> large number of figures and statistical outputs for a large dataset.
>>
>> I am using indexing to retrieve a species name for the title of my graphs-
>> which worked fine. However, I need to italicize these species names.
>>
>> I originally used the paste function, and had no problems with indexing:
>>
>> *main=paste("Yield for ", testsub[1,3], " in management region ",
>> testsub[1,2])*
>>
>> The title looks like: "*Yield for Gadus morhua in management region 4X5Y*"
>>
>> I tried bquote from a related help thread, I tried to emulate it:
>>
>> *spp<-testsub[1,3]*
>> *region<-testsub[1,2]*
>> *
>> *
>> *main=bquote(Yield ~ for ~ italic(.(spp)) ~ in ~ management ~ region ~
>> .(region))*
>>
>> Which doesn't seem to work at all, but when I try not putting anything after
>> the italic:
>>
>> *main=bquote(Yield ~ for ~ italic(.(spp)))*
>>
>> I get: "*Yield for 1*"
>> While *spp=Gadus morhua*
>>
>> I'm at wit's end, I tried to read about substitute, expression, and eval
>> functions in the hopes I can figure it out, but I am lost!
>>
>> Thanks for any help!
>>
>> Cheers,
>>
>> -Jeremy N
>>
>> Undergraduate Researcher in Macroecology
>> University of Ottawa
>> Department of Biology
>>
>> Ad astra per alia porci!
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Italicized title from index

2011-03-31 Thread Henrique Dallazuanna
Try this:

plot(1, main = bquote("Yield  for " ~ italic(.(spp)) ~ "in management
region" ~ .(region)))

On Thu, Mar 31, 2011 at 2:35 AM, Jeremy Newman  wrote:
> Hi all!
>
> I've written a handy script that uses a for loop to allow me to generate a
> large number of figures and statistical outputs for a large dataset.
>
> I am using indexing to retrieve a species name for the title of my graphs-
> which worked fine. However, I need to italicize these species names.
>
> I originally used the paste function, and had no problems with indexing:
>
> *main=paste("Yield for ", testsub[1,3], " in management region ",
> testsub[1,2])*
>
> The title looks like: "*Yield for Gadus morhua in management region 4X5Y*"
>
> I tried bquote from a related help thread, I tried to emulate it:
>
> *spp<-testsub[1,3]*
> *region<-testsub[1,2]*
> *
> *
> *main=bquote(Yield ~ for ~ italic(.(spp)) ~ in ~ management ~ region ~
> .(region))*
>
> Which doesn't seem to work at all, but when I try not putting anything after
> the italic:
>
> *main=bquote(Yield ~ for ~ italic(.(spp)))*
>
> I get: "*Yield for 1*"
> While *spp=Gadus morhua*
>
> I'm at wit's end, I tried to read about substitute, expression, and eval
> functions in the hopes I can figure it out, but I am lost!
>
> Thanks for any help!
>
> Cheers,
>
> -Jeremy N
>
> Undergraduate Researcher in Macroecology
> University of Ottawa
> Department of Biology
>
> Ad astra per alia porci!
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Lists of tables and conditional statements

2011-03-30 Thread Henrique Dallazuanna
Try this:

 lapply(l, function(x)x[x[,'Sum'] == 3,])

On Wed, Mar 30, 2011 at 7:38 PM, Herbert, Alan G  wrote:
> Hi R-users,
>
> I have a list containing numeric tables of differing row length. I want to 
> make a new list that contains only rows from tables with a "Sum" greater than 
> 3, plus the names of each table. I was wondering whether there is an elegant 
> way to do this using apply of related functions as this list has many 
> thousands of such tables.
>
> Here is an example of the list
>
>
> $AACS
>
>                        POOL
>
> INFO                     pool1 pool2 pool6 pool7 pool8 pool.all Sum
>
>  12:125561133:novel         0     0     0     0     1        0   1
>
>  12:125570904:novel         0     0     0     0     1        0   1
>
>  12:125571014:novel         0     1     0     0     0        0   1
>
>  12:125571038:novel         0     0     0     1     0        0   1
>
>  12:125575996:novel         0     0     0     1     0        0   1
>
>  12:125591844:rs2297478     1     0     1     0     0        1   3
>
>  12:125599114:novel         0     0     0     1     0        0   1
>
>  12:125612668:novel         0     0     0     0     1        0   1
>
>  12:125612839:rs900411      1     0     1     0     1        1   4
>
>  12:125626650:novel         0     0     0     0     1        0   1
>
>  12:125626737:novel         0     0     0     1     0        0   1
>
>
>
> $AADAC
>
>                        POOL
>
> INFO                     pool1 pool2 pool5 pool6 pool7 pool8 pool.all Sum
>
>  3:151542411:novel          0     0     0     0     1     0        1   2
>
>  3:151542412:novel          0     0     0     0     1     0        1   2
>
>  3:151542643:novel          0     1     0     0     0     0        0   1
>
>  3:151545322:rs2410836      0     1     0     0     0     0        1   2
>
>  3:151545323:rs62272918     0     1     0     0     0     0        1   2
>
>  3:151545509:novel          0     0     1     0     0     0        1   2
>
>  3:151545601:rs1803155      1     1     1     1     1     1        1   7
>
>  3:151545721:novel          0     0     1     0     0     0        0   1
>
>  3:151545802:novel          0     0     0     0     1     0        0   1
>
>  3:151545824:novel          0     1     0     0     0     0        0   1
>
>
> Thanks for your help
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] summing values by week - based on daily dates - but with some dates missing

2011-03-30 Thread Henrique Dallazuanna
This puts 'NA' in the first week of the year.

Take a look on the code below:

2009.52 %% 1


On Wed, Mar 30, 2011 at 6:35 PM, Dimitri Liakhovitski
 wrote:
> Henrique, this is beautiful, thank you so much.
> This is a great and correct solution.
>
> A stupid question: what does the line is.na(wk) <- wk %% 1 == 0 do?
> Thank you!
> Dimitri
>
> On Wed, Mar 30, 2011 at 5:25 PM, Henrique Dallazuanna  
> wrote:
>> You're right:
>>
>> wk <- as.numeric(format(myframe$dates, "%Y.%W"))
>> is.na(wk) <- wk %% 1 == 0
>> solution<-aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
>>
>>
>> On Wed, Mar 30, 2011 at 6:10 PM, Dimitri Liakhovitski
>>  wrote:
>>> Yes, zoo! That's what I forgot. It's great.
>>> Henrique, thanks a lot! One question:
>>>
>>> if the data are as I originally posted - then week numbered 52 is
>>> actually the very first week (it straddles 2008-2009).
>>> What if the data much longer (like in the code below - same as before,
>>> but more dates) so that we have more than 1 year to deal with.
>>> It looks like this code is lumping everything into 52 weeks. And my
>>> goal is to keep each week independent. If I have 2 years, then it
>>> should be 100+ weeks. Makes sense?
>>> Thank you!
>>>
>>> ### Creating a longer example data set:
>>> mydates<-rep(seq(as.Date("2008-12-29"), length = 500, by = "day"),2)
>>> myfactor<-c(rep("group.1",500),rep("group.2",500))
>>> set.seed(123)
>>> myvalues<-runif(1000,0,1)
>>> myframe<-data.frame(dates=mydates,group=myfactor,value=myvalues)
>>> (myframe)
>>> dim(myframe)
>>>
>>> ## Removing same rows (dates) unsystematically:
>>> set.seed(123)
>>> removed.group1<-sample(1:500,size=150,replace=F)
>>> set.seed(456)
>>> removed.group2<-sample(501:1000,size=150,replace=F)
>>> to.remove<-c(removed.group1,removed.group2);length(to.remove)
>>> to.remove<-to.remove[order(to.remove)]
>>> myframe<-myframe[-to.remove,]
>>> (myframe)
>>> dim(myframe)
>>> names(myframe)
>>>
>>> library(zoo)
>>> wk <- as.numeric(format(myframe$dates, '%W'))
>>> is.na(wk) <- wk == 0
>>> solution<-aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
>>> solution<-solution[order(solution$group),]
>>> write.csv(solution,file="test.csv",row.names=F)
>>>
>>>
>>>
>>> On Wed, Mar 30, 2011 at 4:45 PM, Henrique Dallazuanna  
>>> wrote:
>>>> Try this:
>>>>
>>>> library(zoo)
>>>> wk <- as.numeric(format(myframe$dates, '%W'))
>>>> is.na(wk) <- wk == 0
>>>> aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
>>>>
>>>>
>>>>
>>>> On Wed, Mar 30, 2011 at 4:35 PM, Dimitri Liakhovitski
>>>>  wrote:
>>>>> Henrique, this is great, thank you!
>>>>>
>>>>> It's almost what I was looking for! Only one small thing - it doesn't
>>>>> "merge" the results for weeks that "straddle" 2 years. In my example -
>>>>> last week of year 2008 and the very first week of 2009 are one week.
>>>>> Any way to "join them"?
>>>>> Asking because in reality I'll have many years and hundreds of groups
>>>>> - hence, it'll be hard to do it manually.
>>>>>
>>>>>
>>>>> BTW - does format(dates,"%Y.%W") always consider weeks as starting with 
>>>>> Mondays?
>>>>>
>>>>> Thank you very much!
>>>>> Dimitri
>>>>>
>>>>>
>>>>> On Wed, Mar 30, 2011 at 2:55 PM, Henrique Dallazuanna  
>>>>> wrote:
>>>>>> Try this:
>>>>>>
>>>>>> aggregate(value ~ group + format(dates, "%Y.%W"), myframe, FUN = sum)
>>>>>>
>>>>>>
>>>>>> On Wed, Mar 30, 2011 at 11:23 AM, Dimitri Liakhovitski
>>>>>>  wrote:
>>>>>>> Dear everybody,
>>>>>>>
>>>>>>> I have the following challenge. I have a data set with 2 subgroups,
>>>>>>> dates (days), and corresponding values (see example code below).
>>>>>>> Within each subgroup: I need to aggre

Re: [R] summing values by week - based on daily dates - but with some dates missing

2011-03-30 Thread Henrique Dallazuanna
You're right:

wk <- as.numeric(format(myframe$dates, "%Y.%W"))
is.na(wk) <- wk %% 1 == 0
solution<-aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)


On Wed, Mar 30, 2011 at 6:10 PM, Dimitri Liakhovitski
 wrote:
> Yes, zoo! That's what I forgot. It's great.
> Henrique, thanks a lot! One question:
>
> if the data are as I originally posted - then week numbered 52 is
> actually the very first week (it straddles 2008-2009).
> What if the data much longer (like in the code below - same as before,
> but more dates) so that we have more than 1 year to deal with.
> It looks like this code is lumping everything into 52 weeks. And my
> goal is to keep each week independent. If I have 2 years, then it
> should be 100+ weeks. Makes sense?
> Thank you!
>
> ### Creating a longer example data set:
> mydates<-rep(seq(as.Date("2008-12-29"), length = 500, by = "day"),2)
> myfactor<-c(rep("group.1",500),rep("group.2",500))
> set.seed(123)
> myvalues<-runif(1000,0,1)
> myframe<-data.frame(dates=mydates,group=myfactor,value=myvalues)
> (myframe)
> dim(myframe)
>
> ## Removing same rows (dates) unsystematically:
> set.seed(123)
> removed.group1<-sample(1:500,size=150,replace=F)
> set.seed(456)
> removed.group2<-sample(501:1000,size=150,replace=F)
> to.remove<-c(removed.group1,removed.group2);length(to.remove)
> to.remove<-to.remove[order(to.remove)]
> myframe<-myframe[-to.remove,]
> (myframe)
> dim(myframe)
> names(myframe)
>
> library(zoo)
> wk <- as.numeric(format(myframe$dates, '%W'))
> is.na(wk) <- wk == 0
> solution<-aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
> solution<-solution[order(solution$group),]
> write.csv(solution,file="test.csv",row.names=F)
>
>
>
> On Wed, Mar 30, 2011 at 4:45 PM, Henrique Dallazuanna  
> wrote:
>> Try this:
>>
>> library(zoo)
>> wk <- as.numeric(format(myframe$dates, '%W'))
>> is.na(wk) <- wk == 0
>> aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)
>>
>>
>>
>> On Wed, Mar 30, 2011 at 4:35 PM, Dimitri Liakhovitski
>>  wrote:
>>> Henrique, this is great, thank you!
>>>
>>> It's almost what I was looking for! Only one small thing - it doesn't
>>> "merge" the results for weeks that "straddle" 2 years. In my example -
>>> last week of year 2008 and the very first week of 2009 are one week.
>>> Any way to "join them"?
>>> Asking because in reality I'll have many years and hundreds of groups
>>> - hence, it'll be hard to do it manually.
>>>
>>>
>>> BTW - does format(dates,"%Y.%W") always consider weeks as starting with 
>>> Mondays?
>>>
>>> Thank you very much!
>>> Dimitri
>>>
>>>
>>> On Wed, Mar 30, 2011 at 2:55 PM, Henrique Dallazuanna  
>>> wrote:
>>>> Try this:
>>>>
>>>> aggregate(value ~ group + format(dates, "%Y.%W"), myframe, FUN = sum)
>>>>
>>>>
>>>> On Wed, Mar 30, 2011 at 11:23 AM, Dimitri Liakhovitski
>>>>  wrote:
>>>>> Dear everybody,
>>>>>
>>>>> I have the following challenge. I have a data set with 2 subgroups,
>>>>> dates (days), and corresponding values (see example code below).
>>>>> Within each subgroup: I need to aggregate (sum) the values by week -
>>>>> for weeks that start on a Monday (for example, 2008-12-29 was a
>>>>> Monday).
>>>>> I find it difficult because I have missing dates in my data - so that
>>>>> sometimes I don't even have the date for some Mondays. So, I can't
>>>>> write a proper loop.
>>>>> I want my output to look something like this:
>>>>> group   dates   value
>>>>> group.1 2008-12-29  3.0937
>>>>> group.1 2009-01-05  3.8833
>>>>> group.1 2009-01-12  1.362
>>>>> ...
>>>>> group.2 2008-12-29  2.250
>>>>> group.2 2009-01-05  1.4057
>>>>> group.2 2009-01-12  3.4411
>>>>> ...
>>>>>
>>>>> Thanks a lot for your suggestions! The code is below:
>>>>> Dimitri
>>>>>
>>>>> ### Creating example data set:
>>>>> mydates<-rep(seq(as.Date("2008-12-29"), length = 43, by = "day"),2)
>>>>> myfactor<-c(rep("group.1",43),rep(&quo

Re: [R] summing values by week - based on daily dates - but with some dates missing

2011-03-30 Thread Henrique Dallazuanna
Try this:

library(zoo)
wk <- as.numeric(format(myframe$dates, '%W'))
is.na(wk) <- wk == 0
aggregate(value ~ group + na.locf(wk), myframe, FUN = sum)



On Wed, Mar 30, 2011 at 4:35 PM, Dimitri Liakhovitski
 wrote:
> Henrique, this is great, thank you!
>
> It's almost what I was looking for! Only one small thing - it doesn't
> "merge" the results for weeks that "straddle" 2 years. In my example -
> last week of year 2008 and the very first week of 2009 are one week.
> Any way to "join them"?
> Asking because in reality I'll have many years and hundreds of groups
> - hence, it'll be hard to do it manually.
>
>
> BTW - does format(dates,"%Y.%W") always consider weeks as starting with 
> Mondays?
>
> Thank you very much!
> Dimitri
>
>
> On Wed, Mar 30, 2011 at 2:55 PM, Henrique Dallazuanna  
> wrote:
>> Try this:
>>
>> aggregate(value ~ group + format(dates, "%Y.%W"), myframe, FUN = sum)
>>
>>
>> On Wed, Mar 30, 2011 at 11:23 AM, Dimitri Liakhovitski
>>  wrote:
>>> Dear everybody,
>>>
>>> I have the following challenge. I have a data set with 2 subgroups,
>>> dates (days), and corresponding values (see example code below).
>>> Within each subgroup: I need to aggregate (sum) the values by week -
>>> for weeks that start on a Monday (for example, 2008-12-29 was a
>>> Monday).
>>> I find it difficult because I have missing dates in my data - so that
>>> sometimes I don't even have the date for some Mondays. So, I can't
>>> write a proper loop.
>>> I want my output to look something like this:
>>> group   dates   value
>>> group.1 2008-12-29  3.0937
>>> group.1 2009-01-05  3.8833
>>> group.1 2009-01-12  1.362
>>> ...
>>> group.2 2008-12-29  2.250
>>> group.2 2009-01-05  1.4057
>>> group.2 2009-01-12  3.4411
>>> ...
>>>
>>> Thanks a lot for your suggestions! The code is below:
>>> Dimitri
>>>
>>> ### Creating example data set:
>>> mydates<-rep(seq(as.Date("2008-12-29"), length = 43, by = "day"),2)
>>> myfactor<-c(rep("group.1",43),rep("group.2",43))
>>> set.seed(123)
>>> myvalues<-runif(86,0,1)
>>> myframe<-data.frame(dates=mydates,group=myfactor,value=myvalues)
>>> (myframe)
>>> dim(myframe)
>>>
>>> ## Removing same rows (dates) unsystematically:
>>> set.seed(123)
>>> removed.group1<-sample(1:43,size=11,replace=F)
>>> set.seed(456)
>>> removed.group2<-sample(44:86,size=11,replace=F)
>>> to.remove<-c(removed.group1,removed.group2);length(to.remove)
>>> to.remove<-to.remove[order(to.remove)]
>>> myframe<-myframe[-to.remove,]
>>> (myframe)
>>>
>>>
>>>
>>> --
>>> Dimitri Liakhovitski
>>> Ninah Consulting
>>> www.ninah.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.
>>>
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>
>
>
> --
> Dimitri Liakhovitski
> Ninah Consulting
> www.ninah.com
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 to define new operator in R?

2011-03-30 Thread Henrique Dallazuanna
Try this:

`%a%` <- function(x, y)paste(x, y, sep = ',')
 2 %a% 3


On Wed, Mar 30, 2011 at 1:04 PM, Chuanlong Du  wrote:
> Hello, everyone!
>
> Does anyone know how make some symbols have special means in R? For example,
> we know that "+" in R means the sum of the two operand on its left and
> right. I want to define some operators in R by myself. Is this possible?
>
> Regards!
>
> --
> Chuanlong Du
> Department of Statistcis
> Iowa State University
> Ames, IA, US 50011
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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 can we modify attributes of files in Windows Systems using R?

2011-03-30 Thread Henrique Dallazuanna
You've tried:


shell("ATTRIB +H C:\\your_file_name")

?

On Wed, Mar 30, 2011 at 12:59 PM, Chuanlong Du  wrote:
> Hello!
>
> Does any one know how to modify attributes of files (hide, read only and
> etc) in Windows Systems using R? I tried to use shell to call system
> command, but it seems that it doesn't work well. Sometimes it works but
> sometimes not.
>
> Regards!
>
> --
> Chuanlong Du
> Department of Statistcis
> Iowa State University
> Ames, IA, US 50011
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] summing values by week - based on daily dates - but with some dates missing

2011-03-30 Thread Henrique Dallazuanna
Try this:

aggregate(value ~ group + format(dates, "%Y.%W"), myframe, FUN = sum)


On Wed, Mar 30, 2011 at 11:23 AM, Dimitri Liakhovitski
 wrote:
> Dear everybody,
>
> I have the following challenge. I have a data set with 2 subgroups,
> dates (days), and corresponding values (see example code below).
> Within each subgroup: I need to aggregate (sum) the values by week -
> for weeks that start on a Monday (for example, 2008-12-29 was a
> Monday).
> I find it difficult because I have missing dates in my data - so that
> sometimes I don't even have the date for some Mondays. So, I can't
> write a proper loop.
> I want my output to look something like this:
> group   dates   value
> group.1 2008-12-29  3.0937
> group.1 2009-01-05  3.8833
> group.1 2009-01-12  1.362
> ...
> group.2 2008-12-29  2.250
> group.2 2009-01-05  1.4057
> group.2 2009-01-12  3.4411
> ...
>
> Thanks a lot for your suggestions! The code is below:
> Dimitri
>
> ### Creating example data set:
> mydates<-rep(seq(as.Date("2008-12-29"), length = 43, by = "day"),2)
> myfactor<-c(rep("group.1",43),rep("group.2",43))
> set.seed(123)
> myvalues<-runif(86,0,1)
> myframe<-data.frame(dates=mydates,group=myfactor,value=myvalues)
> (myframe)
> dim(myframe)
>
> ## Removing same rows (dates) unsystematically:
> set.seed(123)
> removed.group1<-sample(1:43,size=11,replace=F)
> set.seed(456)
> removed.group2<-sample(44:86,size=11,replace=F)
> to.remove<-c(removed.group1,removed.group2);length(to.remove)
> to.remove<-to.remove[order(to.remove)]
> myframe<-myframe[-to.remove,]
> (myframe)
>
>
>
> --
> Dimitri Liakhovitski
> Ninah Consulting
> www.ninah.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] fonts in mosaic

2011-03-30 Thread Henrique Dallazuanna
Try this:

windowsFonts(calibri = windowsFont("Calibri"))

mosaic(UCBAdmissions, labeling_args = list(
  gp_labels = gpar(fontsize = 12, fontfamily = "calibri"),
  gp_varnames = gpar(fontsize = 16, fontfamily = "calibri")
))

On Wed, Mar 30, 2011 at 3:25 PM, Erich Neuwirth
 wrote:
> Achim
> I simply want to replace the font R uses on mosaic (whatever it is)
> by a font of my choice (say Calibri or Arial)
> because I need to embed the R charts in a PowerPoint
> presentation and want the fonts to match.
> And I want the most simple way of accomplishing this.
> I worked my way through the strucplot vignette,
> but I could not extract enough information there.
> Is there some information about the proper font names
> to use in R?
>
>
>> Personally, I simply change the size of the device I'm plotting on. When
>> I plot on a large device, the fonts will be relatively smaller, and vice
>> > versa. This is what I do when including graphics in PDF files (papers,
>> > slides, reports, etc.).
>> >
>> > For fine control, you can set the arguments of the labeling function
>> > employed. ?strucplot shows that the default is ?labeling_border which
>> > has several arguments. For example you can set the graphical parameters
>> > of the labels (gp_labels) or the graphical parameters of the variable
>> > names (gp_varnames). Both arguments take ?gpar lists ("grid" graphical
>> > parameters). For example you may do
>> >
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] save ordinary numerical calculations as pdf

2011-03-30 Thread Henrique Dallazuanna
Take a look in ?Sweave

On Wed, Mar 30, 2011 at 6:51 AM, Maas James Dr (MED)  wrote:
> I'd like to save some calculation outputs as a pdf, to incorporate with 
> others in a document.  I've tried
>
> pdf("filename")
> name_of_object_to_output
> dev.off()
>
> but it doesn't seem to work, appears that this pdf function is for graphics?
>
> Is there a way to output numerical objects to pdf?
>
> Thanks
>
> J
>
> Dr. Jim Maas
> University of East Anglia
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Quick recode of -999 to NA in R

2011-03-30 Thread Henrique Dallazuanna
Try:

dat0 <- read.table('tim1.dat', na = -999)

On Wed, Mar 30, 2011 at 10:15 AM, Christopher Desjardins
 wrote:
> Hi,
> I am trying to write a loop to recode my data from -999 to NA in R. What's
> the most efficient way to do this? Below is what I'm presently doing, which
> is inefficient. Thanks,
> Chris
>
>
>   dat0 <- read.table("time1.dat")
>
> colnames(dat0) <- c("e1dq", "e1arcp", "e1dev", "s1prcp", "s1nrcp", "s1ints",
> "a1gpar", "a1pias", "a1devt")
>
> dat0[dat0$e1dq==-999.,"e1dq"] <- NA
>
> dat0[dat0$e1arcp==-999.,"e1arcp"] <- NA
>
> dat0[dat0$e1dev==-999.,"e1dev"] <- NA
>
> dat0[dat0$s1prcp==-999.,"s1prcp"] <- NA
>
> dat0[dat0$s1nrcp==-999.,"s1nrcp"] <- NA
>
> dat0[dat0$s1ints==-999.,"s1ints"] <- NA
>
> dat0[dat0$a1gpar==-999.,"a1gpar"] <- NA
>
> dat0[dat0$a1pias==-999.,"a1pias"] <- NA
>
> dat0[dat0$a1devt==-999.,"a1devt"] <- NA
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] create string with " using paste.

2011-03-29 Thread Henrique Dallazuanna
Try this:

cat("Double quotes: \"\n")

On Tue, Mar 29, 2011 at 4:18 PM, Praveen Surendran
 wrote:
> Hi,
>
> I am trying to create a string -      Double quotes : "
> using paste.
>
> a command something like paste('Double','quotes : \"',sep=" ") prints
> "Double quotes : \"" where backslash is also printed.
> Is there a way to print just "?
>
> Regards,
>
> Praveen.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Simple but elusive - expand back from counts

2011-03-29 Thread Henrique Dallazuanna
Try this:

transform(tmp[rep(seq(nrow(tmp)), as.numeric(tmp$V4)),], V4 = 1)

On Tue, Mar 29, 2011 at 3:15 PM, jjap  wrote:
> Dear R-users,
>
> This should be simple but still eludes me:
>
> Given the following
> tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12,
> "abc", 2), 3, 4, byrow=T))
>
> I want to  expand the data to the following form:
>
>  V1 V2  V3 V4
> 1 44 10 abc  1
> 2 44 10 def  1
> 3 44 12 abc  1
> 4 44 12 abc  1
>
> The last row of the original df was duplicated the row by the number in the
> 4th column (which could be expendable being all ones)
> I clumsily tried a few variants of a loop but I am not making any progress.
> Any hints would be greatly appreciated.
> for (i in 1:3){
>  rbind(rep(tmp[i,], temp[i,4])
>  }
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Simple-but-elusive-expand-back-from-counts-tp3415727p3415727.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Ordering data.frame based on class

2011-03-28 Thread Henrique Dallazuanna
Try this:

my_dat[order(my_dat$class, -my_dat$var1, decreasing = TRUE),]

On Mon, Mar 28, 2011 at 5:55 PM, Vincy Pyne  wrote:
> Dear R helpers
>
> Suppose I have a data.frame as given below -
>
> my_dat = data.frame(class = c("XYZ", "XYZ", "XYZ", "XYZ", "XYZ","ABC", "ABC", 
> "ABC", "ABC", "ABC" ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36), 
> var2 = c(1001, 250, 456, 740, 380, 641, 111, 209, 830, 920))
>
>> my_dat
>    class var1 var2
> 1    XYZ   20 1001
> 2    XYZ   14  250
> 3    XYZ   89  456
> 4    XYZ   81  740
> 5    XYZ   17  380
> 6    ABC   44  641
> 7    ABC   36  111
> 8    ABC   41  209
> 9    ABC   11
>  830
> 10   ABC  20  920
>
> I wish to sort above data.frame class-wise on var1. Thus, Ineed to get
>
>
> class    var1    var2
>
>
>
>  XYZ
>  14
>  250
>
>
>  XYZ
>  17
>  380
>
>
>  XYZ
>  20
>  1001
>
>
>  XYZ
>  81
>  740
>
>
>  XYZ
>  89
>  456
>
>
>  ABC
>  11
>  830
>
>
>  ABC
>  20
>  920
>
>
>  ABC
>  36
>  111
>
>
>  ABC
>  41
>  209
>
>
>  ABC
>  44
>  641
>
>
> Kindly guide
>
> Vincy
>
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] add my own calculated conficence interval to a plot

2011-03-28 Thread Henrique Dallazuanna
Try this:

matplot(DF[,c('SexRatio', 'lower', 'upper')], type ='b', pch = 19, col
= c(2, 1, 1))


On Mon, Mar 28, 2011 at 4:25 PM, Simone Santoro  wrote:
>
> Hi,
>
> I have a data frame like this:
> var1=years
> var2=Sex ratio (0 var3=lower 95% confidence interval
> var4=upper 95% confidence interval
>
> Is there a way to add these confidence intervals to a plot like this?
> plot(years,Sex ratio,type="b")
>
> Thanks in advance for any response
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] rep for multiple categories

2011-03-28 Thread Henrique Dallazuanna
Try this:

as.data.frame.table(xtabs(Number ~ SPP + Point + Visit, template))

On Mon, Mar 28, 2011 at 3:43 PM, BORGMANN,Kathi  wrote:
> Hi,
> I am R beginner and am trying to figure out how to generate a complete list 
> of species for every point, visit, and year. The code below is close but does 
> not give me a list of species for every point, visit, and year in my data set.
>
> spplist<-unique(sumPtCt$Species)
> spplength<-length(spplist)
> Pointlist<-unique(sumPtCt$Point)
> Pointlength<-length(Pointlist)
> Visitlist<-unique(sumPtCt$Visit)
> Visitlength<-length(Visitlist)
> Yearlist<-unique(sumPtCt$Year)
> Yearlength<-length(Yearlist)
> s<-rep(spplist, each=Pointlength, Visitlength, Yearlength)
> p<-rep(Pointlist, spplength)
> v<-rep(Visitlist, spplength)
> y<-rep(Yearlist, spplength)
> template<-data.frame(Species=s,Point=p, Visit=v, Year=y)
>
> ###merge template and data and replace NAs with 0
> FinalPtCt<-merge(template, sumPtCt, all=T)
> FinalPtCt$Number[is.na(FinalPtCt$Number)]<-0
>
>
> Essentially I have data that look like this
>  SPP  Point  Visit  Number
> BUFF   1      1       5
> WEGR   1      1       10
> CLGR   1      1       15
> WEGU   2      1        5
> RUDU   2      1       15
> HOGR   2      1        5
>
>
> But I want to generate this
> Spp  Point              Visit                   Number
> BUFF  1               1               5
> WEGR  1               1               10
> CLGR  1               1               15
> WEGU  1               1               0
> RUDU  1               1               0
> HOGR  1               1               0
> WEGU  2               1               5
> RUDU  2               1               15
> HOGR  2               1               5
> BUFF  2               1               0
> WEGR  2               1               0
> CLGR  2               1               0
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] "Holes" in a data frame with time intervals

2011-03-28 Thread Henrique Dallazuanna
Try this:

dif <- na.omit(c(DF$STARTDATE[-1], NA) - DF$ENDDATE)
list(DF$ENDDATE[dif != 1] + 1, DF$ENDDATE[dif != 1] + (dif[dif != 1] - 1))


On Mon, Mar 28, 2011 at 8:56 AM,   wrote:
> Good morning,
>
>
>
> I am facing a problem very easy to solve with a program, but not too
> easy (at least IMHO) with a "declarative" approach.
>
> I have a dataframe df with some information about bank branches with a
> validity time associated (start date/end date, format -MM-DD) to
> some attributes (for example number of employees assigned).
>
>
>
> The following example will clarify this description:
>
>
>
> BANK_ID     BRANCH_ID   EMPLOYEE #  STARTDATE   ENDDATE
>
> B1          A15         30          2001-01-01  2001-10-15
>
> B1          A15         28          2001-10-16  2001-12-31
>
> B1          A15         32          2002-01-01  2003-04-18
>
> B1          A15         33          2003-04-19  2004-12-31
>
> B1          A15         29          2005-03-01  2010-12-31
>
> B1          A15         30          2011-02-12  -12-31
>
> 
> 
> .
>
>
>
> I would like to find the "missing time intervals" ("holes" - in the
> example 2005-01-01 to 2005-02-28 and from 2011-01-01 to 2011-02-11).
>
> The "programmer's way" would be:
>
>
>
> *         Sort the data by "key" + start date
>
> *         For each occurrence add 1 day to end date and compare the
> result with the start date of the following occurrence
>
>
>
> Can someone help me in finding a "declarative" way to do it ?
>
>
>
> Thank you in advance
>
>
>
> Angelo Linardi
>
>
>
>
>
>
>
>
>
>
> ** Le e-mail provenienti dalla Banca d'Italia sono trasmesse in buona fede e 
> non
> comportano alcun vincolo ne' creano obblighi per la Banca stessa, salvo che 
> cio' non
> sia espressamente previsto da un accordo scritto.
> Questa e-mail e' confidenziale. Qualora l'avesse ricevuta per errore, La 
> preghiamo di
> comunicarne via e-mail la ricezione al mittente e di distruggerne il 
> contenuto. La
> informiamo inoltre che l'utilizzo non autorizzato del messaggio o dei suoi 
> allegati
> potrebbe costituire reato. Grazie per la collaborazione.
> -- E-mails from the Bank of Italy are sent in good faith but they are neither 
> binding on
> the Bank nor to be understood as creating any obligation on its part except 
> where
> provided for in a written agreement. This e-mail is confidential. If you have 
> received it
> by mistake, please inform the sender by reply e-mail and delete it from your 
> system.
> Please also note that the unauthorized disclosure or use of the message or any
> attachments could be an offence. Thank you for your cooperation. **
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] "for" loop assistance -

2011-03-25 Thread Henrique Dallazuanna
Try this:

aggregate(x ~ lc1 + id, DF, FUN = mean)

Where DF is your data.frame

On Fri, Mar 25, 2011 at 2:36 PM, Steven Ranney  wrote:
> All –
>
> I have an example data frame
>
> x       lc1     id
> 43.38812035     85      ga1
> 47.55710661     85      ga1
> 47.55710661     85      ga2
> 47.55710661     85      ga2
> 51.99211429     85      ga3
> 51.99211429     85      ga3
> 51.99211429     95      ga1
> 54.78449958     95      ga1
> 54.78449958     95      ga2
> 54.78449958     95      ga2
> 56.70201864     95      ga3
> 56.70201864     95      ga3
> 56.70201864     105     ga1
> 59.66361903     105     ga1
> 59.66361903     105     ga2
> 61.69573564     105     ga2
> 61.69573564     105     ga3
> 61.69573564     105     ga3
> 63.77469479     115     ga1
> 63.77469479     115     ga1
> 64.83191994     115     ga2
> 64.83191994     115     ga2
> 64.83191994     115     ga3
> 66.98222118     115     ga3
> 66.98222118     125     ga1
> 66.98222118     125     ga1
> 66.98222118     125     ga2
> 66.98222118     125     ga2
> 66.98222118     125     ga3
> 66.98222118     125     ga3
>
> and I’m trying to extract means for every lc1 and id level so that I
> would have a data frame that looks like
>
> x.m     lc1     id
> x.1     085     ga1
> x.2     085     ga2
> x.3     085     ga3
> x.4     095     ga1
> x.5     095     ga2
> x.6     095     ga3
> x.7     105     ga1
> x.8     105     ga2
> x.9     105     ga3
> x.10    115     ga1
> x.11    115     ga2
> x.12    115     ga3
> x.13    125     ga1
> x.14    125     ga2
> x.15    125     ga3
>
> Now, I can use brute force to get the second data frame by
>
> write.table(tapply(x[lc1=="085"], id[lc1=="085"], mean), "file.xls", sep=",")
> write.table(tapply(x[lc1=="095"], id[lc1=="095"], mean), “file.xls",
> sep=",", append=T)
> write.table(tapply(x[lc1=="105"], id[lc1=="105"], mean), “file.xls",
> sep=",", append=T)
> etc…
>
> and add the values for the lc1 column in the .xls file until I’ve
> worked my way through every level for lc1 then read the file back into
> R, but this would require a great deal of my time.  (I have 72 levels
> for lc1 and 346 levels for id totalling over 20,000 lines.)
>
> I am confident that there is a simple, more elegant solution available
> to me that I am overlooking.  I am sure that I could use a “for” loop,
> but as someone that is new to R programming, I am unsure of how to go
> about creating the for loop to build the second data frame.  I've
> tried to modify existing for loops that I already have but have been
> unsuccessful.
>
> Do you have any suggestions?
>
> Thank you –
>
> Steven 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Finding the common portion of strings

2011-03-25 Thread Henrique Dallazuanna
Try this:

intersect2 <- function (x, y)
{
y <- as.vector(y)
y[match(as.vector(x), y, 0L)]
}

paste(Reduce(intersect2, strsplit(OBJECTS, NULL)), collapse = '')

On Fri, Mar 25, 2011 at 2:27 PM, Dennis Fisher  wrote:
> Colleagues
>
> R: 2.12.2
> OS X
>
> I have a set of text objects in the form (I am showing 3 of what is more 
> likely to be 20 or so):
>        OBJECTS <- c("abcSOMETHINGCOMMONegf", "xSOMETHINGCOMMONyz", 
> "SOMETHINGCOMMONnme")
>
> As you can see, all contain "SOMETHINGCOMMON" and the position varies.  But, 
> I don't know what that "SOMETHINGCOMMON" is.
>
> Is there an efficient means to find the common string of characters between 
> all of the objects?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] rbind a heterogeneous row

2011-03-22 Thread Henrique Dallazuanna
You need a list object indeed of a vector, try this:

rbind(df, dreps = c(rep(list(TRUE), 7), 5, 0))

On Tue, Mar 22, 2011 at 10:12 PM, Alexy Khrabrov  wrote:
> I have a dataframe with many rows like this:
>
>> df
>                 X1   X2   X3   X4   X5   X6   X7 week         d
> sim1 FALSE TRUE TRUE TRUE TRUE TRUE TRUE    1 0.3064985
>
> sim1 is the rowname, X1..X7,week,d are the column names.  X1..X7 are factors, 
> booleans in this case.
>
> I need to add another row, represented by the following list:
>
> list(rep(T,7),5,0.0)
>
> -- i.e, TRUE in all boolean columns, 5 in the week column, 0.0 in d.  The 
> name of the new row is "dreps".
>
> I used to add fully numeric rows as follows:
>
> df1 <- rbind(df,dreps=c())
>
> But if I do this here,
>
> df1 <- rbind(df,dreps=c(rep(T,7),5,0.0)) -- booleans are converted to 0/1, 
> which is not what I want.
>
> What's the recommended way to specify and bind a heterogeneous row above?
>
> Cheers,
> Alexy
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Computing row differences in new columns

2011-03-21 Thread Henrique Dallazuanna
Try this:

dat$DATE <- as.Date(dat$DATE, "%d-%b-%y")
dat <- cbind(dat, lapply(mapply(tapply, MoreArgs = list(INDEX =
c(dat$SUBJECT, unique(dat$SUBJECT)), FUN = diff),

lapply(dat[,2:3], c, unique(dat$SUBJECT) / NA), SIMPLIFY = FALSE),
unlist))


On Mon, Mar 21, 2011 at 4:38 PM, Roberto Lodeiro Muller
 wrote:
>
> -Original Message-
> From: Roberto Lodeiro Muller 
> To: roberto.mul...@doctor.com
> Sent: Mon, Mar 21, 2011 3:37 pm
> Subject: Re: [R] Computing row differences in new columns
>
>
> Sorry, my data appeared badly formatted to me, so I converted it to plain 
> text:
>
> And just to clarify, for each subject in the first row it should appear the 
> difference to the next row, so that the last entry on each subject would be a 
> NA.
>
> Thanks again for your help
>
> Roberto
>
> SUBJECT    DATE       RESULT     DateDiff   ResultDiff
> 10751      22-Jul-03  3.5
> 10751      13-Feb-04  1.3
> 10751      20-Aug-04  1.6
> 10751      08-Mar-05  1.7
> 10751      30-Aug-05  1.6
> 10751      21-Feb-06  1.3
> 10751      31-Aug-06  1.2
> 10751      27-Feb-07  1.5
> 10751      29-Aug-07  1
> 10752      29-Jul-03  5.9
> 10752      24-Feb-04  5
> 10752      25-Aug-04  3.6
> 10752      11-Mar-05  5.1
> 10752      18-Sep-05  2.2
> 10752      23-Feb-06  3.1
> 10752      24-Aug-06  3.7
> 10752      27-Feb-07  6
>
>
>
>
>
>
> -Original Message-
> From: Roberto Lodeiro Muller 
> To: r-help@r-project.org
> Sent: Mon, Mar 21, 2011 3:23 pm
> Subject: [R] Computing row differences in new columns
>
>
>
> i
> I have the following columns with dates and results, sorted by subject and 
> date.
> 'd like to compute the differences in dates and results for each patient, 
> based
> n the previous row. Obviously the last entry for each subject should be a NA.
>  Which would be the best way to accomplished that ?
> I guess questions like that have been already answered a thousand times, so I
> pologize for asking one more time.
> Thanks
> Roberto
>
>
>
>
>
> SUBJECT
> ate
> esult
> ateDiff
> esultDiff
> 10751
> 2-Jul-03
> .5
>
>
> 0751
> 3-Feb-04
> .3
>
> 10751
> 0-Aug-04
> .6
>
> 10751
> 8-Mar-05
> .7
>
> 10751
> 0-Aug-05
> .6
>
> 10751
> 1-Feb-06
> .3
>
> 10751
> 1-Aug-06
> .2
>
> 10751
> 7-Feb-07
> .5
>
> 10751
> 9-Aug-07
>
>
> 10752
> 9-Jul-03
> .9
>
> 10752
> 4-Feb-04
>
>
> 10752
> 5-Aug-04
> .6
>
> 10752
> 1-Mar-05
> .1
>
> 10752
> 8-Sep-05
> .2
>
> 10752
> 3-Feb-06
> .1
>
> 10752
> 4-Aug-06
> .7
>
> 10752
> 7-Feb-07
>
>
>
>    [[alternative HTML version deleted]]
> __
> -h...@r-project.org mailing list
> ttps://stat.ethz.ch/mailman/listinfo/r-help
> LEASE do read the posting guide http://www.R-project.org/posting-guide.html
> nd 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] string interpolation

2011-03-21 Thread Henrique Dallazuanna
Try this:

sprintf("%s_%s", rep(1:58, each = 2), c("input", "output"))


On Mon, Mar 21, 2011 at 4:03 PM, Justin Haynes  wrote:
> Is there a way to do this in R? I have data in the form:
>
> 57_input  57_output  58_input  58_output  etc.
>
> can i use a for loop (i in 57:n)  that plots only the outputs?  I want
> this to be robust so im not specifying a column id but rather
> something like c++ code,
>
> %s_input, i
>
> is that doable in R?
>
> Thanks,
> justin
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Understanding tryCatch

2011-03-18 Thread Henrique Dallazuanna
Try this:

tryCatch(log(rnorm(10)), warning = function(m)deparse(m$call[[2]]))

Where log(rnorm(10)) is your expr to evaluate.

On Fri, Mar 18, 2011 at 4:04 PM, steven mosher  wrote:
> I've read the help and the archives on tryCatch but I'm still stuggling
> trying to understand how it
> works exactly and how I can use it to get the result I need.
>
> I have a data.frame of urls which point to 11 .zip files. Basically I use
> RCurl to get the list of
> files from a ftp and then reduce that directory dump to the 11 zip files I
> want to download.
>
> Its easy enough to do that in a loop over the elements in data.frame.
>
> The problem is that the site is very inconsistent. All 11 files will
> download, but I will get random
> warnings that the size of some of the files does not match what was
> downloaded.
> So at the end of the loop I may get 5 warnings about the file size not
> matching.
> These files, when tried a second or third time, will eventually download
> properly.
>
> What I want to do is record which files had this download warning.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] subset data frame with condition

2011-03-18 Thread Henrique Dallazuanna
Try this:


subset(pop, (ave(Area, Area, FUN = length) == 1 | ave(Area, Area, FUN
= function(x)cumsum(prop.table(x))) < 0.7 & Area %in% 1:3))


On Fri, Mar 18, 2011 at 2:48 PM, Nicolas Gutierrez  wrote:
> Hello,
>
> One more question.. I have the data.frame "pop":
>
>    xloc yloc  gonad  ind    Ene    W   Area
> 1    23  20   516.74   1     0.02 20.21  1
> 2    23  20  1143.20   1     0.02 20.21  1
> 3    23  20   250.00   1     0.02 20.21  1
> 4    22  15   251.98   1     0.02 18.69  2
> 5    22  15   598.08   1     0.02 18.69  2
> 6    21  19   250.00   1     0.02 20.21  3
> 7    22  20   251.98   1     0.02 18.69  4
> 8    22  20   598.08   1     0.02 18.69  4
>
> and I need to extract 50% (or rounded) of the rows for each Area (from Area
> 1 to 3 only):
>
>    xloc yloc  gonad  ind    Ene    W   Area
> 1    23  20   516.74   1     0.02 20.21  1
> 2    23  20  1143.20   1     0.02 20.21  1
> 4    22  15   251.98   1     0.02 18.69  2
> 6    21  19   250.00   1     0.02 20.21  3
>
> I did this within a loop, but considering my data.frame has more than 10,000
> rows and within other loops it makes my code run forever! Any hints?
> Thanks!!
>
> Nico
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] predict lm doubt

2011-03-18 Thread Henrique Dallazuanna
Your lm args are wrong:

Try this:

predict(lm(Dens_min ~ Velocity, dfTestes3sitesCriptic))

or

predict(lm(Dens_min ~ Velocity_corrected, dfTestes3sitesCriptic))


On Fri, Mar 18, 2011 at 9:45 AM, barbara costa  wrote:
> Hello,
>  does anyone knows this predict is not resulting?
>
> # lm predict
> dfTestes3sitesCriptic$Velocity_corrected <- ifelse
> (dfTestes3sitesCriptic$Season == "A" & dfTestes3sitesCriptic$BeforeAfter ==
> "Before", (dfTestes3sitesCriptic$Velocity * mVel3ABefAfter), (ifelse
> (dfTestes3sitesCriptic$Season == "Sp" & dfTestes3sitesCriptic$BeforeAfter ==
> "Before", (dfTestes3sitesCriptic$Velocity  * mVel3SpBefAfter),
> dfTestes3sitesCriptic$Velocity )))
>
> dfTestes3sitesCriptic$Dens_min_corrected <- predict (lm(
> dfTestes3sitesCriptic$Dens_min ~ dfTestes3sitesCriptic$Velocity,
> dfTestes3sitesCriptic$Velocity_corrected))
>
>
> just for help:
> Code_Site Year Season YearSeason Type_Environment BeforeAfter Species_Group
> 31    PPBNoc 1998      A     1998-A    Criptobenthic      Before
> Fish
> 33    PPBNoc 1999     Sp    1999-Sp    Criptobenthic      Before
> Fish
> 35    PPBNoc 2009      A     2009-A    Criptobenthic       After
> Fish
> 37    PPBNoc 2009     Sp    2009-Sp    Criptobenthic       After
> Fish
> 39    PPBNoc 2010      A     2010-A    Criptobenthic       After
> Fish
>   TransectTime_min TransectLenght_m Area_m2 Number Density Velocity
> Dens_min
> 31            15.00               55      55     89    1.62     3.67
> 5.93
> 33            15.00               55      55     50    0.91     3.67
> 3.33
> 35            18.15               45      45    185    4.11     2.48
> 10.20
> 37            10.23               45      45     92    2.04     4.40
> 9.00
> 39            16.92               45      45    251    5.58     2.66
> 14.84
>   Code_Site2 Velocity_corrected
> 31       TRUE               2.58
> 33       TRUE               3.25
> 35       TRUE               2.48
> 37       TRUE               4.40
> 39       TRUE               2.66
>
>
>
> Thanks a lot.
> Barbara
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Replace split with regex for speed ?

2011-03-18 Thread Henrique Dallazuanna
Try this:

 sub("\\.(\\d+)$", "\\1", ts)


On Thu, Mar 17, 2011 at 11:01 PM, rivercode  wrote:
>
> Have timestamp in format HH:MM:SS.MMM.UUU and need to remove the last "." so
> it is in format HH:MM:SS.MMMUUU.
>
> What is the fastest way to do this, since it has to be repeated on millions
> of rows. Should I use regex ?
>
> Currently doing it with a string split, which is slow:
>
>  >head(ts)
> [1]  09:30:00.000.245  09:30:00.000.256  09:30:00.000.633  09:30:00.001.309
> 09:30:00.003.635  09:30:00.026.370
>
>
>  ts = strsplit(ts, ".", fixed = TRUE)
>  ts=lapply(ts, function(x) { paste(x[1], ".", x[2], x[3], sep="") } )  #
> Remove last . from timestamp, from HH:MM:SS.MMM.UUU to HH:MM:SS.MMMUUU
>  ts = unlist(ts)
>
> Thanks,
> Chris
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Replace-split-with-regex-for-speed-tp3386098p3386098.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] fetch uneven

2011-03-16 Thread Henrique Dallazuanna
Try this:

a <- m[c(TRUE, FALSE)]

On Wed, Mar 16, 2011 at 11:43 AM, rens  wrote:
> Hi
> I have a vector m:
>  m
>  [1] "ABC transporters"
>  [2] "2"
>  [3] "Acetyl-CoA"
>  [4] "1"
>  [5] "Energie"
>  [6] "1"
>  [7] "FAD Biosynthese"
>  [8] "1"
>  [9] "Glyoxylate and dicarboxylate metabolism"
> [10] "1"
> [11] "Transport"
> [12] "1"
> and i want to do take the even or uneven numbers out of them
> you can do it lik this:
> a<-m[c(1,3,5,7,9,11)]
>
> but i want to do this automatic and i never now how long the vector is.
>
> Can someone help me?
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/fetch-uneven-tp3381949p3381949.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] Reorganize data frame

2011-03-16 Thread Henrique Dallazuanna
Try this:

xtabs(Return ~ Date + Ticker, stock.returns)

On Wed, Mar 16, 2011 at 11:37 AM, chris99  wrote:
> Hi group,
>
> I am trying to convert the organization of a data frame so I can do some
> correlations between stocks,
>
> I have something like this:
>
> stock.returns <-
> data.frame(rbind(c("MSFT","20110301",0.05),c("MSFT","20110302",0.01),c("GOOG","20110301",-0.01),c("GOOG","20110302",0.04)))
> colnames(stock.returns) <- c("Ticker","Date","Return")
> stock.returns
>  Ticker     Date Return
> 1   MSFT 20110301   0.05
> 2   MSFT 20110302   0.01
> 3   GOOG 20110301  -0.01
> 4   GOOG 20110302   0.04
>
>
> And want to convert it to this:
>
> stock.returns <-
> data.frame(rbind(c("20110301",0.05,-0.01),c("20110302",0.01,0.04)))
> colnames(stock.returns) <- c("Date","MSFT","GOOG")
> stock.returns
>      Date MSFT  GOOG
> 1 20110301 0.05 -0.01
> 2 20110302 0.01  0.04
>
>
> Can anyone offer any suggestions?
>
> Thanks,
> Chris
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Reorganize-data-frame-tp3381929p3381929.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

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


  1   2   3   4   5   6   7   8   9   10   >