> I'm trying to replicate a C++ code with R.
Notes:
(1) I'd recommend you make the code more modular.
i.e. One function for initial data prep/modelling, one function for
setting up and solving the QP, etc.
This should be easier to debug.
(However, you would probably have to do it to the C++ code f
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 X
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 t
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) c
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
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, invert
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 Chak
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 writ
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)# remove
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 an
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
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 column
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, prob
> 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 t
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:
Hello
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
---Oo-oO
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. (0,2*J-3,
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
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 "minsp
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:
getCurrentAs
20 matches
Mail list logo