Re: [R-es] DUDA LLENAR MATRIZ CREADA

2015-02-25 Thread Jorge I Velez
David, No hay mucho detalle, pero aqui van algunas ideas: 1. Construye una funcion que tome como argumentos los parametros con los que generas tus muestras y construye una lista con los resultados. Cada componente de la lista contendra las *B *muestras sobre las cuales vas a realizar los

Re: [R-es] Rmysql

2015-02-25 Thread Jorge I Velez
Gracias, Javier. Alguien tiene experiencia con Mac? Que tal la comunicacion en OS X? Saludos, Jorge Velez.- 2015-02-26 0:54 GMT+11:00 Javier Marcuzzi javier.ruben.marcu...@gmail.com: Estimados No es una pregunta, pero si una buena noticia, le� que R y mysql en windows ahora se llevan

Re: [R-es] Problema con bucle for

2015-02-24 Thread Jorge I Velez
O solo R sum(combn(x, 2, prod)) [1] 14121 Saludos, Jorge.- 2015-02-24 21:00 GMT+11:00 Carlos Ortega c...@qualityexcellence.es: Hola, Otra forma de hacerlo, es as�: #--- x- c(24,12,45,68,45) sum(apply(combn(x,2),2,prod)) [1] 14121 #--- Y te ahorras los l�os

Re: [R-es] intercalar elementos de vectores

2015-02-24 Thread Jorge I Velez
Fernando, Podrias intentar R a - rep('a', 5) R b - rep('b', 5) R a [1] a a a a a R b [1] b b b b b R c(rbind(a, b)) [1] a b a b a b a b a b Saludos, Jorge.- 2015-02-24 23:49 GMT+11:00 Fernando Macedo ferm...@gmail.com: Buenas a todos. Relato el problema: - tengo un archivo de 316

Re: [R-es] intercalar elementos de vectores

2015-02-24 Thread Jorge I Velez
I Velez escribi�: Fernando, Podrias intentar R a - rep('a', 5) R b - rep('b', 5) R a [1] a a a a a R b [1] b b b b b R c(rbind(a, b)) [1] a b a b a b a b a b Saludos, Jorge.- 2015-02-24 23:49 GMT+11:00 Fernando Macedo ferm...@gmail.com: Buenas a todos. Relato el

Re: [R] Save a plot with a name given as an argument in a function

2015-02-09 Thread Jorge I Velez
Hi Evgenia, Try test2 - function(data, TitleGraph){ pdf(paste0(TitleGraph, .pdf), width = 7, height = 5) plot(data) dev.off() } instead. Take a look at ?paste0 for more information. HTH, Jorge.- On Tue, Feb 10, 2015 at 12:14 AM, Evgenia ev...@aueb.gr wrote: test-function(data,

Re: [R-es] Listas Recursivas

2015-01-29 Thread Jorge I Velez
Hola Jesus, Intenta lo siguiente, donde x es tu w.list: R unlist(sapply(x, '[', 'a')) a a 1 11 R unlist(sapply(x, '[', 'b')) b1 b2 b3 b4 b5 b1 b2 b3 b4 b5 41 42 43 44 45 71 72 73 74 75 R unlist(sapply(x, '[', 'c')) c c X Z Saludos, Jorge.- 2015-01-29 22:37 GMT+11:00 Jesus Herranz

Re: [R-es] Error seleccionando modelos por el AIC

2015-01-29 Thread Jorge I Velez
Hola Javier, La ayuda de ?aictabe establece que la implementacion del AIC no funciona para objetos de clase lmer (a la que pertenecen los modelos ajustados). De ahi el error. La idea es simplemente comparar los modelos basados en el AIC? O tienes pensado algo mas? Si es lo primero, los objetos

Re: [R-es] Ajuste con exponencial

2015-01-28 Thread Jorge I Velez
Hola Hector, No soy experto, pero en http://r.789695.n4.nabble.com/Fitting-weibull-exponential-and-lognormal-distributions-to-left-truncated-data-td869977.html http://www.r-bloggers.com/r-help-follow-up-truncated-exponential/ http://www.jstatsoft.org/v16/c02/paper hay algunas ideas.Espero

Re: [R-es] Simulación de modelo logit con interacción

2015-01-23 Thread Jorge I Velez
Gracias Emilio por el codigo en R. Hace poco estuve revisando una situacion similar a la que ilustras en tu mensaje (i.e., seleccion de modelos e inferencia). Dale una mirada a estos dos articulos: http://www-stat.wharton.upenn.edu/~berkr/PoSI-submit.pdf

[R] Proportion of equal entries in dist()?

2015-01-19 Thread Jorge I Velez
Dear all, Given vectors x and y, I would like to compute the proportion of entries that are equal, that is, mean(x == y). Now, suppose I have the following matrix: n - 1e2 m - 1e4 X - matrix(sample(0:2, m*n, replace = TRUE), ncol = m) I am interested in calculating the above proportion for

Re: [R-es] Abreviar nombres ciéntificos

2015-01-12 Thread Jorge I Velez
Hola Juan Carlos, Quizas lo siguiente pueda serte util: # test R s - Merluccius merluccius R strsplit(s, ) [[1]] [1] Merluccius merluccius R strsplit(s, )[[1]] [1] Merluccius merluccius R s - strsplit(s, )[[1]] R paste0(substr(s[1], 1, 1), ., s[2]) [1] M.merluccius # funcion convertir -

Re: [R] non negativity constraints if else function

2014-12-20 Thread Jorge I Velez
What about ifelse(w 0, 0, w) See ?ifelse for more information. Best, Jorge.- On Sat, Dec 20, 2014 at 3:26 PM, Esra Ulasan esra_ula...@icloud.com wrote: Hello, I have tried the solve the non-negativity constraint if else function in R. But I have done something wrong because it still

Re: [R] keep only the first value of a numeric sequence

2014-12-15 Thread Jorge I Velez
Dear jeff6868, Here is one way: ifelse(with(data, c(0, diff(mydata))) != 1, 0, 1) You could also take a look at ?rle HTH, Jorge.- On Mon, Dec 15, 2014 at 9:33 PM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Hello dear R-helpers, I have a small problem in my algorithm. I have

Re: [R] Creating a new column from a series of columns

2014-10-31 Thread Jorge I Velez
Dear Dennis, Assuming that your data.frame() is called dd, the following should get you started: colnames(dd[,-1])[apply(dd[,-1], 1, function(x) which(x == 'Yes'))] HTH, Jorge.- On Sat, Nov 1, 2014 at 12:32 PM, Fisher Dennis fis...@plessthan.com wrote: R 3.1.1 OS X Colleagues, I have a

Re: [R-es] Matrices complejas

2014-10-19 Thread Jorge I Velez
Carlos, Una forma de resolverlo es usando la funcion ?rmultinom Saludos, Jorge.- 2014-10-19 20:32 GMT+11:00 Carlos Hern�ndez-Castellano carlos.hernandezcastell...@gmail.com: Saludos compa�eros/as. Consideren una matriz de n columnas y n filas. Quiero distribuir aleatoriamente 6 n�meros

Re: [R-es] Como se hace el operador o (OR) para seleccionar dos o mas niveles de un vector ?

2014-09-03 Thread Jorge I Velez
Hola Eric, Revisa ?%in% Saludos, Jorge.- 2014-09-04 8:41 GMT+10:00 eric ericconchamu...@gmail.com: Estimados, tengo un data.frame con una columna que tiene tres diferentes niveles (aunque la columna no es propiamente de un factor, son solo tres letras diferentes), por ejemplo c, t y s, y

Re: [R-es] problema con campos que tienen formato fecha

2014-08-25 Thread Jorge I Velez
Hola Angela, Una forma de resolver tu problema es utilizando la funcion difftime. En ?difftime hay varios ejemplos. Observa el argumento units en as.numeric(..., units = 'seconds'). Saludos, Jorge.- 2014-08-26 8:16 GMT+10:00 Angela Andrea Camargo Sanabria angela.andrea.cama...@gmail.com:

Re: [R] print vectors with consecutive numbers

2014-08-22 Thread Jorge I Velez
Hi James, Try mat[, apply(mat, 2, function(x) any(diff(x) == 1))] HTH, Jorge.- On Fri, Aug 22, 2014 at 10:18 PM, James Wei zwei0...@hotmail.com wrote: Hi all, I have a matrix with consecutive and non-consecutive numbers in columns. For example, the first 2 columns have consecutive

Re: [R-es] pregunta

2014-08-20 Thread Jorge I Velez
Buenas noches Javier y Jos�, Estoy en contra de usar attach(), asi que propongo la siguiente alternativa con with(): # paquete require(epicalc) # los argumentos en ... pasan de epicalc:::cc # ver ?cc para mas informacion foo - function(var1, var2, var3, ...){ or1 - cc(var1, var2, ...) or2 -

Re: [R-es] [xtable]

2014-08-18 Thread Jorge I Velez
Hola Ernesto, Te sugiero trabajar con el paquete texreg: Philip Leifeld (2013). texreg: Conversion of Statistical Model Output in R to LaTeX and HTML Tables. Journal of Statistical Software, 55(8), 1-24. URL http://www.jstatsoft.org/v55/i08/. Saludos, Jorge.- 2014-08-19 9:26 GMT+10:00

Re: [R] data.table/ifelse conditional new variable question

2014-08-17 Thread Jorge I Velez
, Aug 16, 2014 at 6:48 PM, Jorge I Velez jorgeivanve...@gmail.com wrote: Dear Kate, Assuming you have nuclear families, one option would be: x - read.table(textConnection(Family.ID Sample.ID Relationship 14 62 sibling 14 94 father 14 63 sibling 14

Re: [R] data.table/ifelse conditional new variable question

2014-08-17 Thread Jorge I Velez
2702 3456 sibling 0 842 2702 9980 sibling 0 842 3064 3 father 0 0 3064 4 mother 0 0 3064 5sibling 879 880 3064 86 sibling 879 880 3064 87 sibling 879 880 On Sat, Aug 16, 2014 at 9:31 PM, Jorge I Velez jorgeivanve...@gmail.com wrote: Dear Kate, Try

Re: [R] data.table/ifelse conditional new variable question

2014-08-16 Thread Jorge I Velez
Dear Kate, Assuming you have nuclear families, one option would be: x - read.table(textConnection(Family.ID Sample.ID Relationship 14 62 sibling 14 94 father 14 63 sibling 14 59 mother 17 6004 father 17 6003 mother 17 6005

Re: [R] reshape a dataset

2014-08-15 Thread Jorge I Velez
Dear Sohail, Using Jim's data set skdat, two more options would be # first option d - with(skdat, table(ID, lettertag)) names - colnames(d) d - c(list(rownames(d)), lapply(1:ncol(d), function(i) as.numeric(d[,i]))) names(d) - c('ID', names) d # second option d - with(skdat, table(ID,

Re: [R] reshape a dataset

2014-08-15 Thread Jorge I Velez
is a list. How do I covert it back a dataframe? -Sohail On Fri, Aug 15, 2014 at 5:37 AM, Jorge I Velez jorgeivanve...@gmail.com wrote: Dear Sohail, Using Jim's data set skdat, two more options would be # first option d - with(skdat, table(ID, lettertag)) names - colnames(d) d - c

Re: [R-es] leer ficheros excel en R en Ubuntu

2014-08-14 Thread Jorge I Velez
Hola Miguel, A que te refieres con y nada? Obtienes algun error? Algun mensaje? Has probado con scan() y/o readLines()? Saludos, Jorge.- 2014-08-15 7:38 GMT+10:00 Miguel Fiandor Guti�rrez miguel.fiandor.gutier...@gmail.com: Hola, Pens� que esto iba a ser trivial en R, pero me estoy

Re: [R-es] (sin asunto)

2014-08-11 Thread Jorge I Velez
Hola Alfredo, Algunos comentarios/observaciones: 1. No uses attach. Mejor, explora la funcion with() y/o within(). attach es muy peligroso. 2. Solo por curiosidad, como hiciste para crear la tabla usando latabla$ciudad de origen? Supongo que deberia ser latabla$ciudad de origen 3. Lo que

Re: [R] Possible pair of 2 binary vectors

2014-08-09 Thread Jorge I Velez
Dear Ron, What about this? set.seed(123) d - 4 x1 - sample(0:1, d, TRUE) x2 - sample(0:1, d, TRUE) x1 x2 expand.grid(x1 = x1, x2 = x2) See ?expand.grid for more information. Best, Jorge.- On Sat, Aug 9, 2014 at 7:46 PM, Ron Michael ron_michae...@yahoo.com wrote: Hi, Let say I have 2

Re: [R-es] Descargar lista de paquetes zipeados

2014-07-21 Thread Jorge I Velez
Estimado Prof. Di Rienzo, Creo que lo que busca puede hacerlo con la función download.packages() Saludos cordiales, Jorge.- 2014-07-22 14:03 GMT+10:00 Julio Alejandro Di Rienzo dirienzo.ju...@gmail.com: Hola Alguien sabe como descargar una lista de librerías de R en formato zipeado. Por

Re: [R-es] lista de ficheros

2014-07-16 Thread Jorge I Velez
Hola Juan, Una forma es la siguiente: 1. Debes decirle a R donde estan los ficheros. Para ello usa setwd() 2. Determina el nombre de los ficheros. Usa list.files() 3. Toma el nombre de cada fichero, leelo y genera el data.frame() que necesitas. Al exportar el data.frame() usando

Re: [R] Grouped Boxplot

2014-07-11 Thread Jorge I Velez
Dear Anupam, Try boxplot(DISO ~ POS * NODE_CAT, data = yourdata) Another option would be the last example in ?boxplot HTH, Jorge.- On Fri, Jul 11, 2014 at 4:38 PM, anupam sinha anupam.cont...@gmail.com wrote: Dear all, I need some help with plotting boxplots in groups. I have a

Re: [R-es] Conversion date a numeric y vuelta a date

2014-07-11 Thread Jorge I Velez
julio de 2014, 14:34, Jorge I Velez jorgeivanve...@gmail.com escribió: Hola Alberto, Necesitas as.Date(as.numeric(as.Date(Sys.time())), origin = '1970-01-01') Esta parte as.numeric(as.Date(Sys.time())) # 16260 te da el numero de dias que han transcurrido desde Ene 1, 1970. Luego

Re: [R-es] bucle

2014-07-10 Thread Jorge I Velez
Hola Juan Antonio, Has pensado considerar una aproximacion diferente? De ser asi, explora ?cut y ?car:::recode. Saludos, Jorge.- 2014-07-10 16:58 GMT+10:00 juan(uned) j...@edu.uned.es: Estimados compañeros, hoy me ha surgido una duda, quizás trivial, pero que no encuentro sentido. Tengo

Re: [R-es] Conversion date a numeric y vuelta a date

2014-07-09 Thread Jorge I Velez
Hola Alberto, Necesitas as.Date(as.numeric(as.Date(Sys.time())), origin = '1970-01-01') Esta parte as.numeric(as.Date(Sys.time())) # 16260 te da el numero de dias que han transcurrido desde Ene 1, 1970. Luego, utilizando ese dia/año como origen, determinas la fecha actual. Saludos, Jorge.-

Re: [R-es] abrir varios archivos a la vez y colocarlos en un mismo data frame

2014-07-06 Thread Jorge I Velez
Estimado Alejandro, Lo mejor es trabajar con listas, sea creadas antes de o despues de leer los datos (esto ultimo automaticamente desde R). En cuanto a los nombres de las variables, creo que ahorras tiempo y problemas si los incluyes. A continuacion un ejemplo (necesitas el paquete mets): #

Re: [R-es] error al leer una linea desde un archivo de texto

2014-07-04 Thread Jorge I Velez
fuente permanente de dolor de cabeza. Mi recomendaciones usar siempre que podáis UTF-8. Fran El 03/07/2014 9:57, Jorge I Velez escribió: Hola Eric, Me incliniaria mas por un problema de enconding. Intenta agregando enconding = 'latin1' al final de read.csv() A lo mejor enviandonos

Re: [R-es] error al leer una linea desde un archivo de texto

2014-07-03 Thread Jorge I Velez
Hola Eric, Me incliniaria mas por un problema de enconding. Intenta agregando enconding = 'latin1' al final de read.csv() A lo mejor enviandonos tu sessionInfo() podriamos ayudarte un poco mas. Saludos, Jorge.- 2014-07-03 5:32 GMT+10:00 neo ericconchamu...@gmail.com: Estimada comunidad,

Re: [R] From long to wide format

2014-06-30 Thread Jorge I Velez
] - do.call(rbind, r) X }) # user system elapsed # 0.125 0.011 0.074 wide2 - wide1 wide2$id - as.character(wide2$id) wide$id - as.character(wide$id) all.equal(wide, wide2, check.attributes=F) #[1] TRUE A.K. On Sunday, June 29, 2014 11:48 PM, Jorge I Velez jorgeivanve

[R] From long to wide format

2014-06-29 Thread Jorge I Velez
Dear R-help, I am working with some data stored as filename.txt.gz in my working directory. After reading the data in using read.table(), I can see that each of them has four columns (variable, id, outcome, and rate) and the following structure: # sample data x2 - data.frame(variable =

Re: [R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread Jorge I Velez
Hi Kate, You could try sum(X[, 1] == 1 X[, 2] == 1) where X is your data set. HTH, Jorge.- On Sun, Jun 22, 2014 at 12:57 AM, Kate Ignatius kate.ignat...@gmail.com wrote: I have 4 columns, and about 300K plus rows with 0s and 1s. I'm trying to count how many rows satisfy a certain

Re: [R-es] pregunta

2014-06-15 Thread Jorge I Velez
Hola Jose, Me funciona perfectamente: install.packages('ergm') #--- Please select a CRAN mirror for use in this session --- # also installing the dependencies 'statnet.common', 'trust' #snipped require(ergm) #snipped sessionInfo() #R version 3.0.2 Patched (2013-12-11 r64449) #Platform:

Re: [R] barp {plotrix} Start bars at 0 with a vector of positive values

2014-06-13 Thread Jorge I Velez
Hi Pascal, Perhaps I am missing something, but what about changing passing ylim = c(0, 10) to barp()? Best, Jorge.- On Fri, Jun 13, 2014 at 7:50 PM, Pascal Oettli kri...@ymail.com wrote: Dear list, Please consider the following example: library(plotrix) barp(c(2,3,4,5,6,7,8),

Re: [R] How to print something in the same location in console?

2014-06-12 Thread Jorge I Velez
Dear Juan, Perhaps the last example in http://stat.ethz.ch/R-manual/R-devel/library/utils/html/txtProgressBar.html is what you are looking for. Best, Jorge.- On Thu, Jun 12, 2014 at 8:49 PM, Juan Andres Hernandez jhernandezcabr...@gmail.com wrote: Hi I need to print the iteration number of

Re: [R] Problem with rbind.fill

2014-06-01 Thread Jorge I Velez
Hi Bill, You need require(plyr) ?rbind.fill and then the rest of the code you already tried. Best, Jorge.- On Mon, Jun 2, 2014 at 3:49 AM, Bill Bentley valuetr...@gmail.com wrote: The following works as it should... both-rbind(females,males) both workshop gender q1 q2 q3 q4 1

Re: [R] Problem with products in R ?

2014-05-04 Thread Jorge I Velez
Try options(digits = 22) 168988580159 * 36662978 # [1] 6195624596620653568 HTH, Jorge.- On Sun, May 4, 2014 at 10:44 PM, ARTENTOR Diego Tentor diegotento...@gmail.com wrote: Trying algorithm for products with large numbers i encountered a difference between result of 168988580159 *

Re: [R] Return TRUE only for first match of values between matrix and vector.

2014-05-02 Thread Jorge I Velez
Hi Nevil, Try apply(A, 2, function(x) x == B) HTH, Jorge.- On Fri, May 2, 2014 at 6:46 PM, nevil amos nevil.a...@gmail.com wrote: I wish to return True in a matrix for only the first match of a value per row where the value equals that in a vector with the same number of values as rosw

Re: [R] how to extract a part of objects from list ?

2014-05-01 Thread Jorge I Velez
Hi Kristi, Try out1970$smoot HTH, Jorge.- On Fri, May 2, 2014 at 10:00 AM, Kristi Glover kristi.glo...@hotmail.comwrote: Hi R User, I am wonedring how I can extract a part of objects from list. For example str(out1970) List of 8 $ comm : num [1:16, 1:57] 1 1 1 1 1 1 1 1 1 1 ...

Re: [R] Faster way to transform vector [3 8 4 6 1 5] to [2 6 3 5 1 4]

2014-04-26 Thread Jorge I Velez
Hi Xueming, Try (1:length(bo))[rank(bo)] In a function the above would be f - function(x){ N - length(x) (1:N)[rank(x)] } f(bo) # [1] 2 6 3 5 1 4 HTH, Jorge.- On Sat, Apr 26, 2014 at 7:54 PM, xmliu1...@gmail.com xmliu1...@gmail.comwrote: Hi, could anybody help me to find a

Re: [R] for loop to list files

2014-04-21 Thread Jorge I Velez
Hi Beatriz, Try paste(val_mapped_petpe_, 1976:1981, 01.txt, sep=) Best, Jorge.- On Mon, Apr 21, 2014 at 6:43 PM, Beatriz R. Gonzalez Dominguez aguitatie...@hotmail.com wrote: Dear all, I'm trying to create a loop to select a series of files into my computer but I haven't been successful

Re: [R] Selecting numbers not divisible by 3

2014-03-27 Thread Jorge I Velez
Hi there, Try X[X %% 3 == 0] HTH, Jorge.- On Thu, Mar 27, 2014 at 6:46 PM, Prabhakar Ghorpade dr.prabhaka...@gmail.com wrote: Hi, here's my code X - 1:100 I want to select number divisible by 3 out of them how can I select it? ( I tried following X - 1:100 DIV - Y - X/3 But I

Re: [R] Calculations with aggregate data: confidence intervals

2014-03-25 Thread Jorge I Velez
Hi Luigi, Thanks for sending the data in reproducible format. Perhaps something like this? aggregate(my.data[,3], list(my.data[,2]), FUN = function(x) t.test(x)$ conf.int[1:2]) #Group.1 x.1 x.2 #1 Unstimulated 5.296492e+02 2.410510e+03 #2ESAT6 9.105338e+00

Re: [R] plotting vectors of different lengths

2014-03-22 Thread Jorge I Velez
Hi Eliza, Perhaps the following? matpoints(t(dat), type = 'l') HTH, Jorge.- On Sat, Mar 22, 2014 at 10:18 PM, eliza botto eliza_bo...@hotmail.comwrote: Dear useRs, I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5. I wanted to plot them by using

Re: [R] plotting vectors of different lengths

2014-03-22 Thread Jorge I Velez
You are welcome, Eliza. If I understand correctly, the following will do: x - 1:8 y - 1:5 matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0((, r[1], ,, r[2], ))), ncol = length(x)) Best, Jorge.- On Sat, Mar 22, 2014 at 10:37 PM, eliza botto eliza_bo...@hotmail.comwrote: Thankyou

Re: [R] replace duplicates with 0

2014-03-13 Thread Jorge I Velez
Hi Catalin, The following should give you some ideas: set.seed(123) x - rpois(50, 2) x idx - duplicated(x) x[idx] - 0 x Best, Jorge.- On Thu, Mar 13, 2014 at 11:35 PM, catalin roibu catalinro...@gmail.comwrote: Dear all! Is there a possibility to replace all duplicates values in data

Re: [R] dim vector or data.frame

2014-02-14 Thread Jorge I Velez
Hi Berry, What about using NROW(input) ? Best, Jorge.- On Sat, Feb 15, 2014 at 2:26 AM, Berry Boessenkool berryboessenk...@hotmail.com wrote: Hi, In my function, I want to allow input to be a vector or a data.frame. Certain operations need to be done if the length or nrows exceeds one,

Re: [R] impossible to install package

2014-02-12 Thread Jorge I Velez
Dear Eve, See http://cran.r-project.org/web/packages/languageR/index.html The name of the package is languageR, not LanguageR. Best, Jorge.- On Thu, Feb 13, 2014 at 3:39 PM, Eve Dupierrix evedupier...@gmail.comwrote: Hi, I want to install languageR but is doesn't work. I tried it by two

Re: [R] Label point with (x,hat(y))

2013-11-23 Thread Jorge I Velez
Try R plot(1:10) R text(1,3, expression((x, *hat(y)*)), pos=3) Best, Jorge.- On Sun, Nov 24, 2013 at 10:51 AM, David Arnold dwarnol...@suddenlink.netwrote: Hi, I'd like to do this: text(1,3,(x,yhat),pos=3) But using (x,hat(y)). Any suggestions? D. -- View this message in

Re: [R] left transpose

2013-10-21 Thread Jorge I Velez
Dear Dr. Vokey, Here is one approach, although may not be the more efficient: x - matrix(1:8, ncol = 4) x # [,1] [,2] [,3] [,4] #[1,]1357 #[2,]2468 t(x[, ncol(x):1]) # [,1] [,2] #[1,]78 #[2,]56 #[3,]34 #[4,]12

Re: [R] replace Na values with the mean of the column which contains them

2013-07-29 Thread Jorge I Velez
Consider the following: f - function(x){ m - mean(x, na.rm = TRUE) x[is.na(x)] - m x } apply(de, 2, f) HTH, Jorge.- On Tue, Jul 30, 2013 at 2:39 AM, iza.ch1 iza@op.pl wrote: Hi everyone I have a problem with replacing the NA values with the mean of the column which contains them. If

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Jorge I Velez
Dear Andras, Try a[findInterval(b, a)] [1] 8 32 HTH, Jorge.- On Tue, Jun 18, 2013 at 10:34 PM, Andras Farkas motyoc...@yahoo.com wrote: Dear All, would you please provide your thoughts on the following: let us say I have: a -c(1,5,8,15,32,69) b -c(8.5,33) and I would like to

Re: [R] find closest value in a vector based on another vector values

2013-06-18 Thread Jorge I Velez
they may not be minimum? a - c(1, 8, 9) b - c(2,3) Then what are the 2 closest values of a to b? -- Bert On Tue, Jun 18, 2013 at 5:43 AM, Jorge I Velez jorgeivanve...@gmail.com wrote: Dear Andras, Try a[findInterval(b, a)] [1] 8 32 HTH, Jorge.- On Tue, Jun 18, 2013

Re: [R] How can we access an element in a structure

2013-06-11 Thread Jorge I Velez
Hi Miao, Try attributes(test1)[[1]] HTH, Jorge.- On Tue, Jun 11, 2013 at 3:49 PM, jpm miao miao...@gmail.com wrote: Hi, I have a structure, which is the result of a function How can I access the elements in the gradient? dput(test1) structure(-1.17782911684913, gradient =

Re: [R] boot, what am I doing wrong?

2013-06-07 Thread Jorge I Velez
Hi there, You need a function for your statistic: boot(x, function(x, index) mean(x[index]), R = 1000) ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = x, statistic = function(x, index) mean(x[index]), R = 1000) Bootstrap Statistics : original biasstd. error t1*

Re: [R] Subsetting out missing values for a certain variable

2013-06-05 Thread Jorge I Velez
Daniel, You need == instead of =. HTH, Jorge.- Sent from my phone. Please excuse my brevity and misspelling. On Jun 6, 2013, at 10:36 AM, Daniel Tucker dtuck...@u.rochester.edu wrote: Also tried this but results werent any different subset1- subset(dframe, glb_ind=Y | sample==1 |

Re: [R] Refer to Data Frame Name Inside a List

2013-06-04 Thread Jorge I Velez
Try names(ResList) HTH, Jorge.- Sent from my phone. Please excuse my brevity and misspelling. On Jun 5, 2013, at 12:34 AM, Sparks, John James jspa...@uic.edu wrote: Dear R Helpers, I have a fairly complicated list of data frames. To give you an idea of the structure, the top of the str

Re: [R] Repeating sequence elements

2013-05-17 Thread Jorge I Velez
Try rep(1:length(v), v) HTH, Jorge.- On Fri, May 17, 2013 at 8:53 PM, Stefan Petersson ste...@inizio.se wrote: I want to create a sequence, repeating each element according to a vector. I have this: v - c(4, 4, 4, 3, 3, 2) And want to create this: 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5

Re: [R] How can I find negative items from a vector with a short command?

2013-05-08 Thread Jorge I Velez
-32 -128 f[f0] [1] 4 16 64 f[f=4] [1] 16 2013/5/8 Jorge I Velez jorgeivanve...@gmail.com f [ f 0 ] On Wed, May 8, 2013 at 11:54 AM, jpm miao miao...@gmail.com wrote: Hi, I have a vector f with some negative columns. I remember that there is an easy expression that can find out

Re: [R] How can I find negative items from a vector with a short command?

2013-05-07 Thread Jorge I Velez
f [ f 0 ] On Wed, May 8, 2013 at 11:54 AM, jpm miao miao...@gmail.com wrote: Hi, I have a vector f with some negative columns. I remember that there is an easy expression that can find out negative items. Can someone tell me how I can do it? It seems to be f[i such that f[i]0

Re: [R] How can I access the rowname of a data?

2013-05-06 Thread Jorge I Velez
rownames(a) perhaps? HTH, Jorge.- On Mon, May 6, 2013 at 6:03 PM, jpm miao miao...@gmail.com wrote: Hi, Below is the output from an R package. The first column (4, 5, 6, 7, which is unnamed) is the company name (code), while the second column efficiency is the performance of each

Re: [R] R does not subset

2013-05-03 Thread Jorge I Velez
Hi Kasia, You need subset(REC2, INFECTION==Infected ) (note the space after Infected). HTH, Jorge.- On Fri, May 3, 2013 at 7:48 PM, Katarzyna Kulma katarzyna.ku...@gmail.comwrote: Hi everyone, I know there have been several requests regarding subsetting before, but none of them really

Re: [R] Need help on matrix calculation

2013-04-29 Thread Jorge I Velez
Christofer, The following should get you started: r - Mat[match(rownames(Mat), Subscript_Vec),] rownames(r) - Subscript_Vec r HTH, Jorge.- On Mon, Apr 29, 2013 at 11:38 PM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Hello again, Let say I have 1 matrix: Mat - matrix(1:12, 4,

Re: [R] Need help on matrix calculation

2013-04-29 Thread Jorge I Velez
Sorry, the first line should have been Mat[match( Subscript_Vec, rownames(Mat)),] and the rest remains the same. Best, Jorge.- On Mon, Apr 29, 2013 at 11:45 PM, Jorge I Velez jorgeivanve...@gmail.comwrote: Christofer, The following should get you started: r - Mat[match(rownames(Mat

Re: [R] Decomposing a List

2013-04-25 Thread Jorge I Velez
Dear Dr. Harding, Try sapply(L, [, 1) sapply(L, [, 2) HTH, Jorge.- On Thu, Apr 25, 2013 at 8:16 PM, Ted Harding ted.hard...@wlandres.netwrote: Greetings! For some reason I am not managing to work out how to do this (in principle) simple task! As a result of applying strsplit() to a

Re: [R] Looking for a better code for my problem.

2013-04-24 Thread Jorge I Velez
Try subset(Dat, AA == A | (AA == B BB == b)) HTH, Jorge.- On Wed, Apr 24, 2013 at 8:21 PM, Christofer Bogaso bogaso.christo...@gmail.com wrote: Hello again, Let say I have following data: Dat - structure(list(AA = structure(c(3L, 1L, 2L, 1L, 2L, 3L, 3L, 2L, 3L, 1L, 1L, 3L, 3L, 2L, 2L,

Re: [R] subset dataframe

2013-04-22 Thread Jorge I Velez
Mike, You need subset(agoa, agoa$X.1 == AGOA ) instead of subset(agoa, agoa$X.1 == AGOA) (note the space after the last A in AGOA. HTH, Jorge.- On Tue, Apr 23, 2013 at 7:14 AM, Mihai Nica mihain...@yahoo.com wrote: I can't understand what is happening. This is the code and results:

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread Jorge I Velez
Dear Janesh, Here is one way: # note x is a character x - 73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557 k - nchar(x) # digits in x b - 5 #

Re: [R] Error: could not find function invlogit and bayesglm

2013-04-17 Thread Jorge I Velez
Hi Carrington, You also need the boot package (see http://stat.ethz.ch/R-manual/R-patched/library/boot/html/inv.logit.html ) As for the other function, please load the arm package, e.g., require(arm) require(boot) and then you will be able to use the functions mentioned below. HTH, Jorge.-

Re: [R] non linear equation

2013-04-10 Thread Jorge I Velez
Dear Catalin, You can look at ?nls. Alternatively, you could also consider a linear model as follows, where d is your data: # plot your data with(d, plot(cls, proc, las = 1)) # linear model fit - lm(proc ~ I(1/cls) + I((1/cls)^2), data = d) summary(fit) # plotting with(d, plot(cls, proc, las

Re: [R] non linear equation

2013-04-10 Thread Jorge I Velez
the regression coefficients. On 10 April 2013 12:19, Jorge I Velez jorgeivanve...@gmail.com wrote: Dear Catalin, You can look at ?nls. Alternatively, you could also consider a linear model as follows, where d is your data: # plot your data with(d, plot(cls, proc, las = 1)) # linear

Re: [R] Generating a bivariate joint t distribution in R

2013-04-03 Thread Jorge I Velez
Dear Miao, Check require(MASS) ?mvrnorm for some ideas. HTH, Jorge.- On Wed, Apr 3, 2013 at 4:57 PM, jpm miao wrote: Hi, I conduct a panel data estimation and obtain estimators for two of the coefficients beta1 and beta2. R tells me the mean and covariance of the distribution of

Re: [R] 95% Confidence Interval for a p-p plot

2013-04-02 Thread Jorge I Velez
Pablo, Check the qqPlot function in car: require(car) qqPlot(x, dist = gamma, shape = 1.7918012, rate = 0.9458022) Best, Jorge.- On Tue, Apr 2, 2013 at 4:41 AM, pablo.castano wrote: Hi, I want to create upper and lower 95% confidence intervals for a p-p plot of an empirical

Re: [R] Faster way of summing values up based on expand.grid

2013-03-25 Thread Jorge I Velez
Hi Dimitri, If I understood correctly, the following will do: system.time(sum1 - apply(mycombos, 1, function(x) sum(values1[x]))) system.time(sum2 - apply(mycombos, 1, function(x) sum(values2[x]))) system.time(sum3 - apply(mycombos, 1, function(x) sum(values3[x]))) cbind(sum1, sum2, sum3) HTH,

Re: [R] trouble with data frame

2013-03-22 Thread Jorge I Velez
Sahana, The notation df[a,b)] is plain wrong. I think you meant (but I may be mistaken) df[a, b] and I am not still sure if that would work in your example. Have you instead considered subset()? E.g., subset(df, a = 10 b = 10) See ?subset for more details. Also, df is a very bad name

Re: [R] problem subsetting data.frame in R version 2.15.2 for Windows

2013-03-21 Thread Jorge I Velez
Or simply subset(dat, a 0) HTH, Jorge.- On Thu, Mar 21, 2013 at 6:58 PM, Michael Weylandt wrote: On Mar 21, 2013, at 7:39, Pierrick Bruneau pbrun...@gmail.com wrote: Hi Borja, You may issue: attach(data) No -- bad idea -- dangerous -- confusing statefulness, etc. (See

Re: [R] Help on indicator variables

2013-03-21 Thread Jorge I Velez
Try ifelse(ABS ==1 | DEFF == 1, 1, 0) HTH, Jorge.- On Fri, Mar 22, 2013 at 12:02 AM, Tasnuva Tabassum t.tasn...@gmail.comwrote: I have two indicator variables ABS and DEFF. I want to create another indicator variable which will take value 1 if either ABS=1 or DEFF=1. Otherwise, it will

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
Hi Jim, Try either of the following (untested): sum( x[1, ] 12 x[2, ] 12) sum(apply(x, 2, function(x) x[1] 12 x[2] 12)) where x is your 2x1000 matrix. HTH, Jorge.- On Tue, Mar 19, 2013 at 12:03 AM, Jim Silverton wrote: Hi, I have a 2 x 1 matrix of confidence intervals. The

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
Thats cumbersome, Arun. sum(mat1[,1] 12 mat1[,2] 12) [1] 17 will do the job and even faster: system.time(replicate(1, sum(mat1[,1] 12 mat1[,2] 12))) # user system elapsed # 0.067 0.001 0.078 HTH, Jorge.- On Tue, Mar 19, 2013 at 1:06 AM, arun wrote: Hi, Try this:

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
If you don't use apply() it would be even faster: system.time(sum(mat2[,1] 12 mat2[,2] 12)) user system elapsed 0.004 0.000 0.003 Regards, Jorge.- On Tue, Mar 19, 2013 at 1:21 AM, arun wrote: Hi, Jorge's method will be faster. #system.time(res1-sum(apply(mat2,1,function(x)

Re: [R] string split at xth position

2013-03-13 Thread Jorge I Velez
Dear Johannes, May not be the best way, but this looks like what you described: x - c(a1b1,a2b2,a1b2) x [1] a1b1 a2b2 a1b2 substr(x, 1, 2) [1] a1 a2 a1 substr(x, 3, 4) [1] b1 b2 b2 HTH, Jorge.- On Wed, Mar 13, 2013 at 7:37 PM, Johannes Radinger wrote: Hi, I have a vector of strings

Re: [R] merge datas

2013-03-13 Thread Jorge I Velez
Dear Catalun, If I understood your description, please see ?%in% and try subset(x, names(x) %in% c(1834,1876,1901,1928,2006) ) where x is your data. HTH, Jorge.- On Wed, Mar 13, 2013 at 9:25 PM, catalin roibu wrote: Hello all! I have a problem with R. I try to merge data like this:

Re: [R] Extract letters from a column

2013-03-13 Thread Jorge I Velez
Dear SH, Hmmm... what about substr(tempdf$name, 4, 6)) ? HTH, Jorge.- On Thu, Mar 14, 2013 at 1:06 AM, SH empti...@gmail.com wrote: Dear list: I would like to extract three letters from first and second elements in one column and make a new column. For example below, tempdf =

Re: [R] Extract letters from a column

2013-03-13 Thread Jorge I Velez
like to have letters from first and second elements if possible. Thanks for replying, Steve On Wed, Mar 13, 2013 at 10:10 AM, Jorge I Velez jorgeivanve...@gmail.com wrote: Dear SH, Hmmm... what about substr(tempdf$name, 4, 6)) ? HTH, Jorge.- On Thu, Mar 14, 2013 at 1

Re: [R] Extract letters from a column

2013-03-13 Thread Jorge I Velez
and last name and to combine them to make another column 'abb'. The column 'abb' is to be a my final product. I can make column 'abb' using 'paste' function once I have two parts from the first column 'name'. Thanks, Steve On Wed, Mar 13, 2013 at 10:17 AM, Jorge I Velez jorgeivanve

Re: [R] take two columns from a set of lists

2013-03-11 Thread Jorge I Velez
Is the following that you are looking for? unlist(lapply(x.list, [, 2)) HTH, Jorge.- On Mon, Mar 11, 2013 at 9:52 PM, ishi soichi wrote: say I have a matrix and lists like x - matrix(c(12.1, 3.44, 0.1, 3, 12, 33.1, 1.1, 23), nrow=2) x.list - lapply(seq_len(nrow(x)), function(i) x[i,])

Re: [R] transpose lists

2013-03-08 Thread Jorge I Velez
One option would be x - list(c(12.1, 0.1, 12, 1.1), c(3.44, 3, 33.1, 23)) do.call(c, apply(do.call(rbind, x), 2, list)) HTH, Jorge.- On Fri, Mar 8, 2013 at 9:06 PM, ishi soichi soichi...@gmail.com wrote: Thanks. The result should be a list of lists like... x [[1]] [1] 12.10 3.44

Re: [R] How to export data with defined decimal places

2013-03-07 Thread Jorge I Velez
Dear Marin, May be not the cleanest way to do it, but the following seems to work: write.table(as.character(round(pi, 10)), pi.txt, row.names = FALSE, col.names = FALSE, quote = FALSE) Best, Jorge.- On Fri, Mar 8, 2013 at 11:24 AM, Marino David davidmarino...@gmail.comwrote: Hi Bert, I

Re: [R] reduce the size of list

2013-03-07 Thread Jorge I Velez
If I understood correctly, lapply(x, [, 1:3) will do what you want. HTH, Jorge.- On Fri, Mar 8, 2013 at 5:05 PM, ishi soichi wrote: hi. I have a list like x - list(1:10,11:20,21:30) It's a sort of a 3 x 10 matrix in list form. I would like to reduce the dimension of this list. it

Re: [R] How to reference to the `stats` package in academical paper

2013-03-05 Thread Jorge I Velez
Dear Julien, Check citation('stats') HTH, Jorge.- On Wed, Mar 6, 2013 at 12:05 AM, Julien Mvdb julien.m...@gmail.com wrote: The question is in the title. Then, I would like to know how I should refer to the documentation regarding the use of each functions. Thanks, Julien Mehl

Re: [R] recode data according to quantile breaks

2013-02-19 Thread Jorge I Velez
Hi Alain, The following should get you started: apply(df[,-1], 2, function(x) cut(x, breaks = quantile(x), include.lowest = TRUE, labels = 1:4)) Check ?cut and ?apply for more information. HTH, Jorge.- On Tue, Feb 19, 2013 at 9:01 PM, D. Alain wrote: Dear R-List, I would like to recode

<    1   2   3   4   >