On Fri, 19 Mar 2021, Fianu, Emmanuel Senyo writes: > Hello Enrico, > > thanks for the feedback: this is what I have: > As you can see we have to things here: > > "CAP ATM Fwd" and SWT 0.50% fwd > > strsplit(as.character(df),':', '')# separate the column entry into > multiples specified but not organized into tables. > [[1]] > [1] "c(\"CAP ATM Fwd" " -0.49%\", \"SWT 0.50% fwd" " 0.05%\", > \"CAP ATM Fwd" " -0.46%\", \"SWT 0.50% fwd" > [5] " 0.08%\", \"CAP ATM Fwd" " -0.40%\", \"SWT 0.50% fwd" " 0.11%\", > \"CAP ATM Fwd" " -0.32%\", \"SWT 0.50% fwd" > [9] " 0.14%\", \"CAP ATM Fwd" " -0.23%\", \"SWT 0.50% fwd" " 0.17%\", > \"CAP ATM Fwd" " -0.14%\", \"SWT 0.50% fwd" > [13] " 0.20%\", \"CAP ATM Fwd" " -0.05%\", \"SWT 0.50% fwd" " 0.23%\", > \"CAP ATM Fwd" " 0.07%\", \"SWT 0.50% fwd" > [17] " 0.25%\", \"CAP ATM Fwd" " 0.15%\", \"SWT 0.50% fwd" " 0.27%\", > \"CAP ATM Fwd" " 0.22%\", \"SWT 0.50% fwd" > > Many thanks > Emmanuel >
(I put R-SIG-Finance into Cc. again.) As I said, please provide a reproducible example: use ?dput to provide example data, and also describe what you want to achieve. Perhaps this helps: txt <- c("CAP ATM Fwd: -0.49%", "CAP ATM Fwd: -0.49%") spl <- strsplit(txt, ":", fixed = TRUE) ## [[1]] ## [1] "CAP ATM Fwd" " -0.49%" ## ## [[2]] ## [1] "CAP ATM Fwd" " -0.49%" sapply(spl, `[[`, 1) ## column 1 ## [1] "CAP ATM Fwd" "CAP ATM Fwd" sapply(spl, `[[`, 2) ## column 2 ## [1] " -0.49%" " -0.49%" Now you can remove the '%' and call 'as.numeric' and so on.... [...] > On Fri, Mar 19, 2021 at 9:59 AM Enrico Schumann <e...@enricoschumann.net> > wrote: > >> On Fri, 19 Mar 2021, Fianu, Emmanuel Senyo writes: >> >> > Dear All, >> > >> > Please, I am working on raw financial data and would like to have the >> data >> > cleaned. I am working on it a bit further and will be very grateful for >> any >> > idea or support. Below are my codes and results. >> > I would like to have the numbers after the semi-columns separate. >> > >> > >> > Strike<-unlist(c(my.data$Strike)) >> > # >> > # >> > Strike <- sapply(Strike[], trimws) # löscht überflüssige Leerzeichen >> > Strike <- Strike[-1] # löscht die erste Zeile >> > >> > CAP ATM Fwd: -0.49% SWT 0.50% fwd: 0.05% >> > "CAP ATM Fwd: -0.49%" "SWT 0.50% fwd: 0.05%" >> > CAP ATM Fwd: -0.46% SWT 0.50% fwd: 0.08% >> > "CAP ATM Fwd: -0.46%" "SWT 0.50% fwd: 0.08%" >> > CAP ATM Fwd: -0.40% SWT 0.50% fwd: 0.11% >> > "CAP ATM Fwd: -0.40%" "SWT 0.50% fwd: 0.11%" >> > CAP ATM Fwd: -0.32% SWT 0.50% fwd: 0.14% >> > "CAP ATM Fwd: -0.32%" "SWT 0.50% fwd: 0.14%" >> > CAP ATM Fwd: -0.23% SWT 0.50% fwd: 0.17% >> > "CAP ATM Fwd: -0.23%" "SWT 0.50% fwd: 0.17%" >> > CAP ATM Fwd: -0.14% SWT 0.50% fwd: 0.20% >> > "CAP ATM Fwd: -0.14%" "SWT 0.50% fwd: 0.20%" >> > CAP ATM Fwd: -0.05% SWT 0.50% fwd: 0.23% >> > "CAP ATM Fwd: -0.05%" "SWT 0.50% fwd: 0.23%" >> > CAP ATM Fwd: 0.07% SWT 0.50% fwd: 0.25% >> > "CAP ATM Fwd: 0.07%" "SWT 0.50% fwd: 0.25%" >> > >> > Many thanks >> > Emmanuel >> > >> >> Please provide a reproducible example, so that people can help you. >> >> (It's not what you have written, but did you mean "the >> numbers after the colons"? Then perhaps look at >> ?strsplit : >> >> strsplit("CAP ATM Fwd: -0.49%", split = ":", fixed = TRUE) >> ## [[1]] >> ## [1] "CAP ATM Fwd" " -0.49%" >> >> sapply(strsplit("CAP ATM Fwd: -0.49%", ":", fixed = TRUE), `[[`, 2L) >> ## [1] " -0.49%" >> >> ) -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.