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

2021-11-02 Thread Avi Gross via R-help
I have several things I considered about this topic. It is, in general, not possible to do some things in one language or another even if you find a bridge. Python lets you place all kinds of things into a dictionary including many static objects like tuples or even other dictionaries. What is all

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

2021-11-02 Thread Andrew Simmons
cat in R behaves similarly to cat in unix-alikes, sends text to a stdout. Usually, that stdout would be a file, but usually in R it is the R Console. I think it might also help to note the difference between cat and print: x <- "test\n" cat(x) print(x) produces > cat(x) test > print(x) [1] "t

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

2021-11-02 Thread Ivan Krylov
On Tue, 2 Nov 2021 10:18:07 -0700 (PDT) Rich Shepard wrote: > 'corvalis discharge summary\n' > summary(cor_disc) > sd(cor_disc$cfs) > '-\n' In the interactive mode, on the top level of execution, these commands behave as if you had written print(sink('data-summaries.txt')) print

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

2021-11-02 Thread Rich Shepard
On Tue, 2 Nov 2021, Bert Gunter wrote: What do you think these 2 lines are doing? cat ('corvalis discharge summary\n') print(cat) Bert, If I used them in linux cat would display the file (as do more and less) and print() would be replaced with lpr Please consult ?cat . You might also spend

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

2021-11-02 Thread Bert Gunter
What do you think these 2 lines are doing? cat ('corvalis discharge summary\n') print(cat) Please consult ?cat . You might also spend a bit of (more?) time with an R tutorial or two as you seem confused about how assignment (<-) works. Or maybe I'm confused about what is confusing you Bert G

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

2021-11-02 Thread Rich Shepard
On Tue, 2 Nov 2021, Andrew Simmons wrote: You probably want to use cat and print for these lines. These things won't print when not run at the top level, so if you want them to print, you must specify that. Andrew, I modified the file to this: sink('data-summaries.txt') cat ('corvalis dischar

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

2021-11-02 Thread Andrew Simmons
You probably want to use cat and print for these lines. These things won't print when not run at the top level, so if you want them to print, you must specify that. On Tue, Nov 2, 2021, 13:18 Rich Shepard wrote: > I've read ?sink and several web pages about it but it's not working > properly > w

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

2021-11-02 Thread Bill Dunlap
Note that an environment carries a hash table with it, while a named list does not. I think that looking up an entry in a list causes a hash table to be created and thrown away. Here are some timings involving setting and getting various numbers of entries in environments and lists. The times ar

[R] sink() not working as expected

2021-11-02 Thread Rich Shepard
I've read ?sink and several web pages about it but it's not working properly when I have the commands in a script and source() them. The file: library(tidyverse) library(lubridate) sink('data-summaries.txt') 'corvalis discharge summary\n' summary(cor_disc) sd(cor_disc$cfs) '-\n'

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

2021-11-02 Thread Andrew Simmons
If you're thinking about using environments, I would suggest you initialize them like x <- new.env(parent = emptyenv()) Since environments have parent environments, it means that requesting a value from that environment can actually return the value stored in a parent environment (this isn't an

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

2021-11-02 Thread Martin Møller Skarbiniks Pedersen
On Tue, 2 Nov 2021 at 10:48, Yonghua Peng wrote: > > I know this is a newbie question. But how do I implement the hash structure > which is available in other languages (in python it's dict)? > As other posters wrote then environments are the solution. data.frames, vectors and lists are much slow

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

2021-11-02 Thread Rich Shepard
On Tue, 2 Nov 2021, Ivan Krylov wrote: That's because mutate() doesn't, well, mutate its argument. It _returns_ its changes, but it doesn't save them in the original variable. It's your responsibility to assign the result somewhere: Ivan, I realized this after thinking more about the issue.

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

2021-11-02 Thread Rich Shepard
On Mon, 1 Nov 2021, jim holtman wrote: drop the select, or put tz in the select Jim, Thinking more about the process after logging out for the evening it occurred to me that I need to select all columns to retain them in the tibble. I just tried that and, sure enough, that did the job. Thank

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

2021-11-02 Thread Jan van der Laan
Yes. A data.frame is basically a list where all elements are vectors of the same length. So this issue also exists in a data.frame. However, the data.frame construction method will detect this and generate unique names (which also might not be what you want): > data.frame(a=1:3, a=1:3)

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

2021-11-02 Thread Duncan Murdoch
On 02/11/2021 4:13 a.m., Yonghua Peng wrote: I know this is a newbie question. But how do I implement the hash structure which is available in other languages (in python it's dict)? I know there is the list, but list's names can be duplicated here. As Eric said, the environment comes pretty cl

Re: [R] by group

2021-11-02 Thread PIKAL Petr
Hi Although you got several answers, simple aggregate was omitted. > with(dat, aggregate(wt, list(Year=Year, Sex=Sex), mean)) Year Sexx 1 2001 F 12.0 2 2002 F 13.3 3 2003 F 12.0 4 2001 M 15.0 5 2002 M 16.3 6 2003 M 15.0 you can reshape the result >

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

2021-11-02 Thread Yonghua Peng
But for data.frame the colnames can be duplicated. Am I right? Regards. On Tue, Nov 2, 2021 at 6:29 PM Jan van der Laan wrote: > > True, but in a lot of cases where a python user might use a dict an R > user will probably use a list; or when we are talking about arrays of > dicts in python, the

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

2021-11-02 Thread Jan van der Laan
True, but in a lot of cases where a python user might use a dict an R user will probably use a list; or when we are talking about arrays of dicts in python, the R solution will probably be a data.frame (with each dict field in a separate column). Jan On 02-11-2021 11:18, Eric Berger wro

Re: [R] Translation of the charter

2021-11-02 Thread Greg Minshall
hi, Heinz, > You are right - match seems obviously better, but why not do > > x <- c("a","b","c") > match(x, letters[]) no, really, i wasn't sure of the requirements! cheers, Greg __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see h

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

2021-11-02 Thread Eric Berger
One choice is new.env(hash=TRUE) in the base package On Tue, Nov 2, 2021 at 11:48 AM Yonghua Peng wrote: > I know this is a newbie question. But how do I implement the hash structure > which is available in other languages (in python it's dict)? > > I know there is the list, but list's names c

[R] Is there a hash data structure for R

2021-11-02 Thread Yonghua Peng
I know this is a newbie question. But how do I implement the hash structure which is available in other languages (in python it's dict)? I know there is the list, but list's names can be duplicated here. > x <- list(x=1:5,y=month.name,x=3:7) > x $x [1] 1 2 3 4 5 $y [1] "January" "Februar

Re: [R] Translation of the charter

2021-11-02 Thread Heinz Tuechler
Greg, Greg Minshall wrote/hat geschrieben on/am 02.11.2021 08:57: Heinz, x <- c("a","b","c") lettersnum <- 1:length(letters[]) names(lettersnum) <- letters[] lettersnum[x] lettersnum[x] a b c 1 2 3 i'm not sure if the following is obviously better, but one might do b <- match(a, a) n

Re: [R] Translation of the charter

2021-11-02 Thread Greg Minshall
Heinz, > x <- c("a","b","c") > lettersnum <- 1:length(letters[]) > names(lettersnum) <- letters[] > lettersnum[x] > > lettersnum[x] > a b c > 1 2 3 i'm not sure if the following is obviously better, but one might do > b <- match(a, a) > names(b) <- a > b a b c 1 2 3 cheers, Greg _

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

2021-11-02 Thread Ivan Krylov
On Mon, 1 Nov 2021 15:24:47 -0700 (PDT) Rich Shepard wrote: > + mutate( > + sampdt = make_datetime(year, mon, day, hr, min) > + ) <...> > produces the sampdt column, but it, and the timezone, are not present > in the cor_disc tibble That's because mutate() doesn't, well, mutate its argument. I