Re: [R] concatenating columns in data.frame

2021-07-01 Thread Jeff Newmiller
I use parts of the tidyverse frequently, but this post is the best argument I can imagine for learning base R techniques. On July 1, 2021 8:41:06 PM PDT, Avi Gross via R-help wrote: >Micha, > >Others have provided ways in standard R so I will contribute a somewhat >odd solution using the dplyr

Re: [R] List / Matrix to Data Frame

2021-07-01 Thread Avi Gross via R-help
Bill, A Matrix can only contain one kind of data. I ran your code after modifying it to be proper and took a transpose to get it risght-side up: t(wanted) date netIncomegrossProfit 2020-09-30 "2020-09-30" "5741100.00" "10495600.00" 2019-09-30 "2019-09-30" "552560

Re: [R] concatenating columns in data.frame

2021-07-01 Thread Avi Gross via R-help
Micha, Others have provided ways in standard R so I will contribute a somewhat odd solution using the dplyr and related packages in the tidyverse including a sample data.frame/tibble I made. It requires newer versions of R and other packages as it uses some fairly esoteric features including "

Re: [R] List / Matrix to Data Frame

2021-07-01 Thread Bill Dunlap
Does this do what you want? > df <- data.frame(check.names=FALSE, lapply(c(Date="date",netIncome="netIncome",`Gross Profit`="grossProfit"), function(nm)vapply(ISY, "[[", nm, FUN.VALUE=NA_character_))) > str(df) 'data.frame': 36 obs. of 3 variables: $ Date: chr "2020-09-30" "2019-09-30

[R] List / Matrix to Data Frame

2021-07-01 Thread Sparks, John
Hi R-Helpers, I am taking it upon myself to delve into the world of lists for R. In no small part because I appear to have discovered a source of data for an exceptionally good price but that delivers much of that data in json format. So over the last day or so I managed to fight the list proc

Re: [R] get data frame using DBI package

2021-07-01 Thread Jeff Newmiller
Please make the effort to post plain text email... formatted email gets stripped and what remains is often garbled. Most people use dbGetQuery... but reading the help page accessible via ?dbSendQuery should clarify how it should be used. On July 1, 2021 3:36:46 PM PDT, Kai Yang via R-help wro

[R] get data frame using DBI package

2021-07-01 Thread Kai Yang via R-help
Hi List,I use odbc to connect a MSSQL server. When I run the script of "res <- dbSendQuery(con, "SELECT * FROM BIODBX.MECCUNIQUE2")", the res is "Formal class OdbcResult". Can someone help me to modify the code to get a data frame?Thanks,Kai [[alternative HTML version deleted]]

Re: [R] concatenating columns in data.frame

2021-07-01 Thread Eric Berger
Lovely one-liner Bert. Chapeau On Thu, Jul 1, 2021 at 10:16 PM Berry, Charles wrote: > > > > On Jul 1, 2021, at 11:24 AM, Bert Gunter wrote: > > > > Why not simply: > > > > ## reprex > > set.seed(123) > > df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10), > >"C"=s

Re: [R] concatenating columns in data.frame

2021-07-01 Thread Berry, Charles
> On Jul 1, 2021, at 11:24 AM, Bert Gunter wrote: > > Why not simply: > > ## reprex > set.seed(123) > df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10), >"C"=sample(letters,10), "D"=sample(letters, 10)) > df > use_columns = c("D", "B") > > ## one liner > df$com

Re: [R] concatenating columns in data.frame

2021-07-01 Thread Bert Gunter
Why not simply: ## reprex set.seed(123) df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10), "C"=sample(letters,10), "D"=sample(letters, 10)) df use_columns = c("D", "B") ## one liner df$combo_col <- do.call(paste,c(df[,use_columns], sep = "_")) df In case you are wo

Re: [R] concatenating columns in data.frame

2021-07-01 Thread Berry, Charles
> On Jul 1, 2021, at 7:36 AM, Micha Silver wrote: > > I need to create a new data.frame column as a concatenation of existing > character columns. But the number and name of the columns to concatenate > needs to be passed in dynamically. The code below does what I want, but seems > very clu

Re: [R] concatenating columns in data.frame

2021-07-01 Thread Eric Berger
You can do the same steps but without so much intermediate saving to shorten it f <- function(x) { do.call(rbind,lapply(1:nrow(x), function(r) {paste(x[r,], collapse="_")})) } df_combo <- cbind(df,Combo=f(df[,c(4,2)])) HTH, Eric On Thu, Jul 1, 2021 at 5:37 PM Micha Sil

[R] concatenating columns in data.frame

2021-07-01 Thread Micha Silver
I need to create a new data.frame column as a concatenation of existing character columns. But the number and name of the columns to concatenate needs to be passed in dynamically. The code below does what I want, but seems very clumsy. Any suggestions how to improve? df = data.frame("A"=sampl

Re: [R] Unexpected date format coercion

2021-07-01 Thread Enrico Schumann
On Thu, 01 Jul 2021, Jeremie Juste writes: > Hello > > On Thursday, 1 Jul 2021 at 08:25, PIKAL Petr wrote: >> Hm. >> >> Seems to me, that both your codes are wrong but printing in Linux is >> different from Windows. >> >> With >> as.Date("20-12-2020","%Y-%m-%d") >> you say that 20 is year (actua

Re: [R] Unexpected date format coercion

2021-07-01 Thread PIKAL Petr
Hi Maybe you could inspect parse_date_time {lubridate} R Documentation from package lubridate. Or see answers here https://stackoverflow.com/questions/25463523/how-to-convert-variable-with-mixed-date-formats-to-one-format Cheers Petr > -Original Message- > From: Jeremie Juste >

Re: [R] Bibliometix Package Question

2021-07-01 Thread Jim Lemon
Hi Adrianna, I can see why you may be confused about the input file to create the dataframe for bibliometrix. Looking at the 'convert2db' function, it seems to shuffle the various formats to a common order used by other functions. The help page describes that order. I would look at the sample file

Re: [R] Unexpected date format coercion

2021-07-01 Thread Jeremie Juste
Hello On Thursday, 1 Jul 2021 at 08:25, PIKAL Petr wrote: > Hm. > > Seems to me, that both your codes are wrong but printing in Linux is > different from Windows. > > With > as.Date("20-12-2020","%Y-%m-%d") > you say that 20 is year (actually year 20) and 2020 is day and only first > two values

Re: [R] Unexpected date format coercion

2021-07-01 Thread PIKAL Petr
Hm. Seems to me, that both your codes are wrong but printing in Linux is different from Windows. With as.Date("20-12-2020","%Y-%m-%d") you say that 20 is year (actually year 20) and 2020 is day and only first two values are taken (but with some valueas result is NA) I can confirm 4.0.3 in Window

Re: [R] Unexpected date format coercion

2021-07-01 Thread Jim Lemon
Hi Jeremie, Try: as.Date("20-12-2020","%y-%m-%d") [1] "2020-12-20" Jim On Thu, Jul 1, 2021 at 6:16 PM Jeremie Juste wrote: > > Hello, > > I have been surprised when converting a character string to a date with the > following > format, > > in R 4.1.0 (linux debian 10) > > as.Date("20-12-2020",

Re: [R] Unexpected date format coercion

2021-07-01 Thread Uwe Ligges
On 01.07.2021 10:06, Jeremie Juste wrote: Hello, I have been surprised when converting a character string to a date with the following format, in R 4.1.0 (linux debian 10) as.Date("20-12-2020","%Y-%m-%d") [1] "20-12-20" in R 4.0.5 (window 10) as.Date("20-12-2020","%Y-%m-%d") [1] "0020-12

[R] Unexpected date format coercion

2021-07-01 Thread Jeremie Juste
Hello, I have been surprised when converting a character string to a date with the following format, in R 4.1.0 (linux debian 10) as.Date("20-12-2020","%Y-%m-%d") [1] "20-12-20" in R 4.0.5 (window 10) as.Date("20-12-2020","%Y-%m-%d") [1] "0020-12-20" Here I was expecting a blunt and sharp N

[R] Bibliometix Package Question

2021-07-01 Thread Perryman, Adrianna
Hello, My name is Adrianna, I am a student researcher at the University Health Network in Toronto. I am working on a bibliometric analysis and would like to use R. My search involves five databases: MEDLINE (Ovid), AJOL, EMBASE, African Medicus Index and Web of Science. We expect to gather thou