Re: [R] error message from read.csv in loop

2021-07-09 Thread Rui Barradas
Hello, 1. When there are systematic errors, use ?try or, better yet, ?tryCatch. Something like the code below will create a list of errors and read in the data if none occurred. The code starts by creating an empty list for tryCatch results. It uses ?file.path instead of noquote/paste0 to assem

Re: [R] problem for strsplit function

2021-07-09 Thread Rolf Turner
This discussion has developed in such a way that it seems a better subject line would be "problem for the hairsplit function". :-) cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276

Re: [R] problem for strsplit function

2021-07-09 Thread Jeff Newmiller
A bit too fast there, Duncan... x[[c(1,2)]] is illegal. On July 9, 2021 5:16:13 PM PDT, Duncan Murdoch wrote: >On 09/07/2021 6:44 p.m., Bert Gunter wrote: >> OK, I stand somewhat chastised. >> >> But my point still is that what you get when you "extract" depends on >> how you define "extract." D

Re: [R] problem for strsplit function

2021-07-09 Thread Jeff Newmiller
My mental model for the `[` vs `[[` behavior is that `[` indexes multiple results while `[[` indexes only one item. If returning multiple items from a list the result must be a list. For consistency, `[` always returns a list when applied to a list. The double bracket drops the containing list.

Re: [R] problem for strsplit function

2021-07-09 Thread Duncan Murdoch
On 09/07/2021 6:44 p.m., Bert Gunter wrote: OK, I stand somewhat chastised. But my point still is that what you get when you "extract" depends on how you define "extract." Do note that ?"[" yields a help file titled "Extract or Replace Parts of an object"; and afaics, the term "subset" is not ex

Re: [R] problem for strsplit function

2021-07-09 Thread Bert Gunter
"But it takes me a while to get familiar R." Of course. That is true for all of us. Just keep on plugging away and you'll get it. Probably far better than I before too long. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (

Re: [R] problem for strsplit function

2021-07-09 Thread Kai Yang via R-help
Thanks Bert, I'm reading some books now. But it takes me a while to get familiar R. Best, KaiOn Friday, July 9, 2021, 03:06:11 PM PDT, Duncan Murdoch wrote: On 09/07/2021 5:51 p.m., Jeff Newmiller wrote: > "Strictly speaking", Greg is correct, Bert. > > https://cran.r-project.org/doc/

Re: [R] problem for strsplit function

2021-07-09 Thread Bert Gunter
OK, I stand somewhat chastised. But my point still is that what you get when you "extract" depends on how you define "extract." Do note that ?"[" yields a help file titled "Extract or Replace Parts of an object"; and afaics, the term "subset" is not explicitly used as Duncan prefers. The relevant

Re: [R] problem for strsplit function

2021-07-09 Thread Duncan Murdoch
On 09/07/2021 5:51 p.m., Jeff Newmiller wrote: "Strictly speaking", Greg is correct, Bert. https://cran.r-project.org/doc/manuals/r-release/R-lang.html#List-objects Lists in R are vectors. What we colloquially refer to as "vectors" are more precisely referred to as "atomic vectors". And withou

Re: [R] problem for strsplit function

2021-07-09 Thread Jeff Newmiller
"Strictly speaking", Greg is correct, Bert. https://cran.r-project.org/doc/manuals/r-release/R-lang.html#List-objects Lists in R are vectors. What we colloquially refer to as "vectors" are more precisely referred to as "atomic vectors". And without a doubt, this "vector" nature of lists is a ke

Re: [R] problem for strsplit function

2021-07-09 Thread Bert Gunter
"1. a column, when extracted from a data frame, *is* a vector." Strictly speaking, this is false; it depends on exactly what is meant by "extracted." e.g.: > d <- data.frame(col1 = 1:3, col2 = letters[1:3]) > v1 <- d[,2] ## a vector > v2 <- d[[2]] ## the same, i.e > identical(v1,v2) [1] TRUE > v3

Re: [R] How to create a matrix from a list without a for loop

2021-07-09 Thread Duncan Murdoch
On 09/07/2021 3:37 p.m., Laurent Rhelp wrote: Very effective solution, I hope I remember that for the nex time. The key things to remember are that in R a "list" object is a vector whose elements are R objects, and that matrices are just vectors with dimension attributes. Those two ideas a

Re: [R] How to create a matrix from a list without a for loop

2021-07-09 Thread Laurent Rhelp
Very effective solution, I hope I remember that for the nex time. Thank you Le 09/07/2021 à 19:50, David Winsemius a écrit : On 7/9/21 10:40 AM, Laurent Rhelp wrote: Dear R-Help-list,   I have a list init_l containing 16 dataframes and I want to create a matrix 4 x 4 from this list with a

Re: [R] How to create a matrix from a list without a for loop

2021-07-09 Thread Laurent Rhelp
You are right, this extra level disturbed me. Very impressive this solution, thank you very much. Le 09/07/2021 à 19:50, Bill Dunlap a écrit : > Try >    matrix(init_l, nrow=4, ncol=4, > dimnames=list(c("X1","X2","X3","X4"),c("X1","X2","X3","X4"))) > It doesn't give exactly what your code does

Re: [R] error message from read.csv in loop

2021-07-09 Thread Kai Yang via R-help
Hi Migdonio, I did try your code: # Initialize the rr variable as a list. rr <- as.list(rep(NA, nrow(ora))) # Run the for-loop to store all the CSVs in rr. for (j in 1:nrow(ora)) {         mycol  <- ora[j,"fname"]         mycsv  <- paste0(mycol,".csv")         rdcsv  <- noquote(paste0("w:/

Re: [R] problem for strsplit function

2021-07-09 Thread Greg Minshall
Kai, > one more question, how can I know if the function is for column > manipulations or for vector? i still stumble around R code. but, i'd say the following (and look forward to being corrected! :): 1. a column, when extracted from a data frame, *is* a vector. 2. maybe your question is "i

Re: [R] error message from read.csv in loop

2021-07-09 Thread Eric Berger
it complained about ASSAY_DEFINITIONS not about RESPONDENTS. Can you try with the ASSAY_DEFINITIONS file? On Fri, Jul 9, 2021 at 9:10 PM Kai Yang via R-help wrote: > Hello List, > I use for loop to read csv difference file into data frame rr. The data > frame rr will be deleted after a comp

[R] error message from read.csv in loop

2021-07-09 Thread Kai Yang via R-help
Hello List, I use for loop to read csv difference file into data frame rr.  The data frame rr will be deleted after a comparison and go to the next csv file.  Below is my code: for (j in 1:nrow(ora)) {   mycol  <- ora[j,"fname"]   mycsv  <- paste0(mycol,".csv'")   rdcsv  <- noquote(paste0("'w:/pr

Re: [R] How to create a matrix from a list without a for loop

2021-07-09 Thread David Winsemius
On 7/9/21 10:40 AM, Laurent Rhelp wrote: Dear R-Help-list,   I have a list init_l containing 16 dataframes and I want to create a matrix 4 x 4 from this list with a dataframe in every cell of the matrix. I succeeded to do that but my loop is very uggly (cf. below). Could somebody help me to

Re: [R] How to create a matrix from a list without a for loop

2021-07-09 Thread Bill Dunlap
Try matrix(init_l, nrow=4, ncol=4, dimnames=list(c("X1","X2","X3","X4"),c("X1","X2","X3","X4"))) It doesn't give exactly what your code does, but your code introduces an extra level of "list", which you may not want. -Bill On Fri, Jul 9, 2021 at 10:40 AM Laurent Rhelp wrote: > Dear R-Help-li

[R] How to create a matrix from a list without a for loop

2021-07-09 Thread Laurent Rhelp
Dear R-Help-list,   I have a list init_l containing 16 dataframes and I want to create a matrix 4 x 4 from this list with a dataframe in every cell of the matrix. I succeeded to do that but my loop is very uggly (cf. below). Could somebody help me to write nice R code to do this loop ? Thank

Re: [R] How to estimate the parameter for many variable?

2021-07-09 Thread SITI AISYAH ZAKARIA
Dear Rui ang Jim, Thank you very much. Thank you Rui Barradas, I already tried using your coding and I'm grateful I got the answer. ok now, I have some condition on the location parameter which is cyclic condition. So, I will add another 2 variables for the column. and the condition for locati

Re: [R] How to estimate the parameter for many variable?

2021-07-09 Thread Rui Barradas
Hello, With the condition for the location it can be estimated like the following. fit_list2 <- gev_fit_list <- lapply(Ozone_weekly2, gev.fit, ydat = ti, mul = c(2, 3), show = FALSE) mle_params2 <- t(sapply(fit_list2, '[[', 'mle')) # assign column names colnames(mle_params2) <- c("location",