Re: [R] Split

2020-09-22 Thread Bert Gunter
That was still slower and doesn't quite give what was requested: > cbind(F1,utils::strcapture("([^_]*)_(.*)", F1$text, proto=data.frame(Before_=character(), After_=character( ID1 ID2 text Before_ After_ 1 A1 B1 NONE 2 A1 B1 cf_12 cf 12 3 A1 B1 NONE 4 A2 B2

[R-es] ORDEN GRÁFICO POR MESES

2020-09-22 Thread Jesus MARTIN F.
Hola, Estoy haciendo un gráfico con: # ## GRAFICO BARRAS : VALORES AL DEBE MENSUALIZADO ggplot(Diario_S2, aes(x=mes_AAA, by = MES , y=ARS_DEB))+ # ASIGNAR VARIABLES geom_bar(stat="identity", width=0.7,

Re: [R] Split

2020-09-22 Thread Bill Dunlap
Another way to make columns out of the stuff before and after the underscore, with NAs if there is no underscore, is utils::strcapture("([^_]*)_(.*)", F1$text, proto=data.frame(Before_=character(), After_=character())) -Bill On Tue, Sep 22, 2020 at 4:25 PM Bert Gunter wrote: > To be clear, I

Re: [R] Split

2020-09-22 Thread Bert Gunter
Oh, if efficiency is a consideration, then my code is about 15 times as fast as Rui's: > F2 <- F1[rep(1:5,1e6),] ## 5 million rows ##Rui's > system.time({ + F2$Y1 <- +grepl("_", F2$text) + tmp <- strsplit(as.character(F2$text), "_") + tmp <- lapply(tmp, function(x) if(length(x) == 1)

Re: [R] Split

2020-09-22 Thread Val
Thank you all for the help! LMH, Yes I would like to see the alternative. I am using this for a large data set and if the alternative is more efficient than this then I would be happy. On Tue, Sep 22, 2020 at 6:25 PM Bert Gunter wrote: > > To be clear, I think Rui's solution is perfectly fine

Re: [R] Split

2020-09-22 Thread Bert Gunter
To be clear, I think Rui's solution is perfectly fine and probably better than what I offer below. But just for fun, I wanted to do it without the lapply(). Here is one way. I think my comments suffice to explain. > ## which are the non "_" indices? > wh <- grep("_",F1$text, fixed = TRUE,

Re: [R-es] EXTRAER MES EN LETRAS Y CASTELLANO

2020-09-22 Thread Javier Marcuzzi
Estimado Jesus Martín Comprendo lo que usted desea, pero puede entrar en problemas. Los problemas son si necesita la fecha para algún cálculo, gráfico, etc. Tocar fechas es complicado. Mire lo siguiente https://cran.r-project.org/web/packages/date/date.pdf Javier Rubén Marcuzzi El mar., 22

[R-es] EXTRAER MES EN LETRAS Y CASTELLANO

2020-09-22 Thread Jesus MARTIN F.
Buenas tardes, Estoy precisando generar una nueva variable que contenga el mes en tres letras, por ejemplo: ENE , FEB, MAR , ABR y así sucesivamente a partir de los valores que ahora tengo en el Dataset, que son 1, 2, 3, 4 y así sucesivamente. Entiendo que sería con mutate, pero consulto

Re: [R] Help with the Error Message in R "Error in 1:nchid : result would be too long a vector"

2020-09-22 Thread Rui Barradas
Hello, Please keep this on the list so that others can give their contribution. If you have reshaped your data can you post the code you ran to reshape it? Right now we only have the original attachment, in wide format, not the long format data. Rui Barradas Às 21:55 de 22/09/20, Rahul

Re: [R] Split

2020-09-22 Thread LMH
Sometimes it just makes more sense to pre-process your data and get it into the format you need. It just depends on whether you are more comfortable programing in R or in some other text manipulation language like bash/sed/awk/grep etc. If you know how to do this with other tools, you could

Re: [R-es] Encontrar un dato y añadirlo a otra columna

2020-09-22 Thread Juan Carlos Lopez Mesa
Hola, prueba con esto df %>% mutate(var = parse_number(nombre1)) Saludos El mar., 22 sept. 2020 a las 15:46, Samura . () escribió: > Buenas, > A ver si alguien sabe como hacer lo siguiente: > > Tengo un df con letras y numeros, quiero que si me detecta un numero en > concreto me añada dicho

[R-es] Encontrar un dato y añadirlo a otra columna

2020-09-22 Thread Samura .
Buenas, A ver si alguien sabe como hacer lo siguiente: Tengo un df con letras y numeros, quiero que si me detecta un numero en concreto me a�ada dicho numero en otra columna. Algo asi df<-data.frame(c("AV 23","PEPE 34","QWE","AV 24","WERRR ER34","AV 25")) colnames(df)<-c("nombre1")

Re: [R-es] expresiones regulares

2020-09-22 Thread Samura .
Muchas gracias aunque no era lo que buscaba pq la estructura de los datos es cambiante y no se le puede aplicar una funcion "fija". Al final estoy usando gsub caso a caso. De: Eric Enviado: domingo, 20 de septiembre de 2020 20:41 Para: Carlos Ortega ; Samura

Re: [R] Split

2020-09-22 Thread Rui Barradas
Hello, A base R solution with strsplit, like in your code. F1$Y1 <- +grepl("_", F1$text) tmp <- strsplit(as.character(F1$text), "_") tmp <- lapply(tmp, function(x) if(length(x) == 1) c(x, ".") else x) tmp <- do.call(rbind, tmp) colnames(tmp) <- c("X1", "X2") F1 <- cbind(F1[-3], tmp)#

Re: [R] Split

2020-09-22 Thread Rui Barradas
Hello, Something like this? F1$Y1 <- +grepl("_", F1$text) F1 <- F1[c(1, 2, 4, 3)] F1 <- tidyr::separate(F1, text, into = c("X1", "X2"), sep = "_", fill = "right") F1 Hope this helps, Rui Barradas Às 19:55 de 22/09/20, Val escreveu: HI All, I am trying to create new columns based on

[R] Split

2020-09-22 Thread Val
HI All, I am trying to create new columns based on another column string content. First I want to identify rows that contain a particular string. If it contains, I want to split the string and create two variables. Here is my sample of data. F1<-read.table(text="ID1 ID2 text A1 B1 NONE A1

Re: [R] Help with the Error Message in R "Error in 1:nchid : result would be too long a vector"

2020-09-22 Thread Rahul Chakraborty
David, My apologies with the first one. I was checking different tutorials on mlogit where they were using mlogit.data, so I ended up using it. I am not getting what you are saying by the "duplicates in first two columns". See, my first column is IND which identifies my individuals, second

Re: [R] Help with the Error Message in R "Error in 1:nchid : result would be too long a vector"

2020-09-22 Thread Rui Barradas
Hello, I apologize if the rest of quotes prior to David's email are missing, for some reason today my mail client is not including them. As for the question, there are two other problems: 1) Alt_name is misspelled, it should be ALT_name; 2) the data is in wide, not long, format. A 3rd,

Re: [R] text on curve

2020-09-22 Thread Berry, Charles
> On Sep 22, 2020, at 1:10 AM, Jinsong Zhao wrote: > > Hi there, > > I write a simple function that could place text along a curve. Since I am not > familiar with the operation of rotating graphical elements, e.g., text, > rectangle, etc., I hope you could give suggestions or hints on how

Re: [R] Help with the Error Message in R "Error in 1:nchid : result would be too long a vector"

2020-09-22 Thread David Winsemius
You were told two things about your code: 1) mlogit.data is deprecated by the package authors, so use dfidx. 2) dfidx does not allow duplicate ids in the first two columns. Which one of those are you asserting is not accurate? -- David. On 9/21/20 10:20 PM, Rahul Chakraborty wrote:

Re: [R] aggregate semi-hourly data not 00-24 but 9-9

2020-09-22 Thread Stefano Sofia
Yes, thank you so much. Stefano (oo) --oOO--( )--OOo Stefano Sofia PhD Civil Protection - Marche Region Meteo Section Snow Section Via del Colle Ameno 5 60126 Torrette di Ancona, Ancona Uff: 071 806 7743 E-mail: stefano.so...@regione.marche.it

Re: [R] Quadratic programming

2020-09-22 Thread Maija Sirkjärvi
I really appreciate you helping me with this! I just don't seem to figure it out. (1) I don't know why you think bvec should be a matrix. The documentation clearly says it should be a vector (implying not a matrix). - I've written it in a form of a matrix with one row and 2*J-3 columns.

Re: [R] aggregate semi-hourly data not 00-24 but 9-9

2020-09-22 Thread Eric Berger
Thanks Jeff. Stefano, per Jeff's comment, you can replace the line df1$data_POSIXminus9 <- df1$data_POSIX - lubridate::hours(9) by df1$data_POSIXminus9 <- df1$data_POSIX - as.difftime(9,units="hours") On Mon, Sep 21, 2020 at 8:06 PM Jeff Newmiller wrote: > > The base R as.difftime function is

Re: [R] text on curve

2020-09-22 Thread Jim Lemon
Hi Jinsong, This is similar to the "arctext" function in plotrix. I don't want to do all the trig right now, but I would suggest placing the characters on the curve and then offsetting them a constant amount at right angles to the slope of the curve at each letter. I would first try having a

[R] text on curve

2020-09-22 Thread Jinsong Zhao
Hi there, I write a simple function that could place text along a curve. Since I am not familiar with the operation of rotating graphical elements, e.g., text, rectangle, etc., I hope you could give suggestions or hints on how to improve it. Thanks in advance. # Here is the code: