Re: [R] Is there a hash data structure for R

2021-11-03 Thread Abby Spurdle
Here's an interesting article: Collections in R: Review and Proposal Timothy Barry The R Journal doi: 10.32614/RJ-2018-037 https://journal.r-project.org/archive/2018/RJ-2018-037/RJ-2018-037.pdf On Tue, Nov 2, 2021 at 10:48 PM Yonghua Peng wrote: > > I know this is a

Re: [R] sink() not working as expected [RESOLVED]

2021-11-03 Thread Rich Shepard
On Wed, 3 Nov 2021, Rui Barradas wrote: You do not assign the pipe output, so put the print statement as the last instruction of the pipe. The following works. # file: rhelp.R library(dplyr) mtcars %>% select(mpg, cyl, disp, hp, am) %>% mutate( sampdt = c("automatic", "manual")[am + 1L]

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Jim Lemon
Hi Gabrielle, I get the feeling that you are trying to merge data in which each file contains different variables, but the same subjects have contributed the data. This a very wild guess, but it may provide some insight. # assume that subjects are identified by a variable named "subjectID" #

Re: [R] names.data.frame?

2021-11-03 Thread Leonard Mada via R-help
Thank you very much. Indeed, NextMethod() is the correct way and is working fine. There are some alternatives (as pointed out). Although I am still trying to figure out what would be the best design strategy of such a class. Note: - I wanted to exclude the "coeff" column from the returned

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Duncan Murdoch
On 02/11/2021 6:30 p.m., gabrielle aban steinberg wrote: Hello, I would like to merge 18 csv files into a master data csv file, but each file has a different number of columns (mostly found in one or more of the other cvs files) and different number of rows. I have tried something like the

Re: [R] sink() not working as expected

2021-11-03 Thread Rui Barradas
Hello, You do not assign the pipe output, so put the print statement as the last instruction of the pipe. The following works. # file: rhelp.R library(dplyr) mtcars %>% select(mpg, cyl, disp, hp, am) %>% mutate( sampdt = c("automatic", "manual")[am + 1L] ) %>% print() Then,

Re: [R] names.data.frame?

2021-11-03 Thread Duncan Murdoch
On 03/11/2021 2:54 p.m., Andrew Simmons wrote: First, your signature for names.pm is wrong. It should look something more like: names.pm <- function (x) { } As for the body of the function, you might do something like: names.pm <- function (x) { NextMethod() } but you don't need to

Re: [R] names.data.frame?

2021-11-03 Thread Rui Barradas
Hello, I too would expected NextMethod to work but the following seems to be simpler. "names" is an attribute, so should be accessible with attr. names.pm = function(p) { attr(p, "names") } p = data.frame(x=1:3, coeff=1) class(p) = c("pm", class(p)); names(p) #[1] "x" "coeff"

Re: [R] sink() not working as expected

2021-11-03 Thread Rich Shepard
On Wed, 3 Nov 2021, Ivan Krylov wrote: instead. When you source() a script, auto-printing is not performed. This is explained in the first paragraph of ?source, but not ?sink. If you want to source() scripts and rely on their output (including sink()), you'll need to print() results explicitly.

Re: [R] What to do when problems() returns nothing

2021-11-03 Thread Rich Shepard
On Wed, 3 Nov 2021, Bert Gunter wrote: More to the point, the tidyverse galaxy tries to largely replace R's standard functionality and has its own help forum. So I think you should post there, rather than here, for questions about it: https://www.tidyverse.org/help/ Bert, Thank you very

Re: [R] What to do when problems() returns nothing

2021-11-03 Thread Bert Gunter
None of this is for R's *standard* packages. The posting guide, linked below, says: "For questions about functions in standard packages distributed with R (see the FAQ Add-on packages in R ), ask questions on R-help. If the

Re: [R] names.data.frame?

2021-11-03 Thread Ivan Krylov
On Wed, 3 Nov 2021 20:35:58 +0200 Leonard Mada via R-help wrote: > class(p) = c("pm", class(p)); Does NextMethod() work for you? -- Best regards, Ivan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] names.data.frame?

2021-11-03 Thread Andrew Simmons
First, your signature for names.pm is wrong. It should look something more like: names.pm <- function (x) { } As for the body of the function, you might do something like: names.pm <- function (x) { NextMethod() } but you don't need to define a names method if you're just going to call

[R] What to do when problems() returns nothing

2021-11-03 Thread Rich Shepard
When I source the import_data.R script now I get errors that tell me to look at problems(). I enter that function name but there's no return. Reading ?problems I learned that stop_for_problems(x) should stop the process when a problem occurs, so I added that function to each data file; for

[R] names.data.frame?

2021-11-03 Thread Leonard Mada via R-help
Dear List members, Is there a way to access the default names() function? I tried the following: # Multi-variable polynomial p = data.frame(x=1:3, coeff=1) class(p) = c("pm", class(p)); names.pm = function(p) { # .Primitive("names")(p) # does NOT function # .Internal("names")(p) # does

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Avi Gross via R-help
I am not clear why Python came up on this forum. Yes, you can do all sorts of stuff in Python (or other languages) in ways similar or not to doing them in R. The topic here was reading in data from multiple CSV files and I saw no mention about whether some columns are supposed to be of type

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Jeff Newmiller
>(Maybe the R Studio free trial/usage is underpowered for my project?) - R is a computer language, as well as a program for interpreting R source code. - RStudio Desktop is an editor with "features" intended to make using R easy. It cannot "do" anything without R being installed. - R is

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Jeff Newmiller
Data type in a CSV is always character until inferred otherwise... it is not necessary nor even easier to manipulate files with Python if you are planning to use R to manipulate the data further with R. Just use the colClasses="character" argument for read.csv. On November 3, 2021 9:47:03 AM

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Bill Dunlap
The error message arises because you are sometimes delimiting character strings using non-ASCII open and close double quotes, '“' and '”', instead of the old-fashioned ones, '"', which have no open or close variants. This is a language syntax error, so R didn't try to compute anything. The

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Robert Knight
It might be easier to settle on the desired final csv layout and use Python to copy the rows via line reads. Python doesn't care about the data type in a given "cell", numeric or char, whereas the type errors R would encounter would make the task very difficult. On Wed, Nov 3, 2021, 10:36 AM

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Bert Gunter
I should have added that once read into R, the collection of data frames (presumably) can also be saved in one .Rdata file via save() **without** first combining them into a list. I still prefer keeping them together as one list in R, but that's up to you. Bert Gunter "The trouble with having an

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Bert Gunter
1. Think more carefully about the appropriate data structure for what you wish to do. It's unlikely to be .csv files, however. In the absence of the above, a simple (but perhaps inappropriate) default is: 2. Read the files into R and combine into a list.(You will need to read about lists in R if

Re: [R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Avi Gross via R-help
Gabrielle, Why would you expect that to work? rbind() binds rows of internal R data structures that are some variety of data.frame with exactly the same columns in the same order into a larger object of that type. You are not providing rbind() with the names of variables holding the info but

Re: [R] Is there a hash data structure for R

2021-11-03 Thread Avi Gross via R-help
Jack, I was agreeing with you and pointing out that although changing names of columns to be unique has a positive side, it makes it hard to use for anything that needs to look like either a set or a bag and of course a dictionary/hash. All the above want to put things in using some identifier and

[R] Fwd: Merging multiple csv files to new file

2021-11-03 Thread gabrielle aban steinberg
Hello, I would like to merge 18 csv files into a master data csv file, but each file has a different number of columns (mostly found in one or more of the other cvs files) and different number of rows. I have tried something like the following in R Studio (cloud): all_data_fit_files <-

Re: [R] tidyverse: read_csv() misses column [RESOLVED]

2021-11-03 Thread Rich Shepard
From krylov.r...@gmail.com Tue Nov 2 14:22:05 2021 instead. When you source() a script, auto-printing is not performed. This is explained in the first paragraph of ?source, but not ?sink. If you want to source() scripts and rely on their output (including sink()), you'll need to print()

Re: [R] Is there a hash data structure for R

2021-11-03 Thread Jan van der Laan
On 03-11-2021 00:42, Avi Gross via R-help wrote: Finally, someone mentioned how creating a data.frame with duplicate names for columns is not a problem as it can automagically CHANGE them to be unique. That is a HUGE problem for using that as a dictionary as the new name will not be known