similar to: Is this a bug in `[`?

Displaying 20 results from an estimated 20000 matches similar to: "Is this a bug in `[`?"

2018 Aug 04
3
Is this a bug in `[`?
?s 15:51 de 04/08/2018, I?aki ?car escreveu: > El s?b., 4 ago. 2018 a las 15:32, Rui Barradas > (<ruipbarradas at sapo.pt>) escribi?: >> >> Hello, >> >> Maybe I am not understanding how negative indexing works but >> >> 1) This is right. >> >> (1:10)[-1] >> #[1] 2 3 4 5 6 7 8 9 10 >> >> 2) Are these right? They
2018 Aug 05
2
Is this a bug in `[`?
Thanks. This is exactly the doubt I had. Rui Barradas ?s 05:26 de 05/08/2018, Kenny Bell escreveu: > This should more clearly illustrate the issue: > > c(1, 2, 3, 4)[-seq_len(4)] > #> numeric(0) > c(1, 2, 3, 4)[-seq_len(3)] > #> [1] 4 > c(1, 2, 3, 4)[-seq_len(2)] > #> [1] 3 4 > c(1, 2, 3, 4)[-seq_len(1)] > #> [1] 2 3 4 > c(1, 2, 3, 4)[-seq_len(0)]
2018 Aug 05
2
Is this a bug in `[`?
El dom., 5 ago. 2018 a las 6:27, Kenny Bell (<kmbell56 at gmail.com>) escribi?: > > This should more clearly illustrate the issue: > > c(1, 2, 3, 4)[-seq_len(4)] > #> numeric(0) > c(1, 2, 3, 4)[-seq_len(3)] > #> [1] 4 > c(1, 2, 3, 4)[-seq_len(2)] > #> [1] 3 4 > c(1, 2, 3, 4)[-seq_len(1)] > #> [1] 2 3 4 > c(1, 2, 3, 4)[-seq_len(0)] > #>
2012 Nov 14
5
aggregate combination data
Dear R users, I want to aggregate all *d *data from all combination of n *plots* taken by k. Thank very much! My data is like that: plot d 1 14 1 13 1 12 1 14 1 18 1 20 1 21 1 43 1 108 1 43 2 41 2 61 2 83 2 61 2 84 2 45 2 21 2 12 2 11 ... 100 10 100 12 -- --- Catalin-Constantin ROIBU Forestry engineer, PhD Forestry Faculty of Suceava
2013 Jun 23
1
Scaling Statistical
Short question: Is it possible to use statistical tests, like the Augmented Dickey-Fuller test, in functions with for-loops? If not, are there any alternative ways to scale measures? Detailed explanation: I am working with time-series, and I want to flag curves that are not stationary and which display pulses, trends, or level shifts. >df DATE ID VALUE2012-03-06 1
2012 Aug 31
7
splits with 0s in middle columns
Hi, A column of my df looks like A 10/20/30 40/20 60/10/10/5 80/10 I want to split it such that the last column has the last composition and if there are not enough the middle columns get the 0s. That way my df would look like A1 A2 A3 A4 10 20 0 30 40 0 0 20 60 10 10 5 80 0 0 10 How can I do that ?? [[alternative HTML version deleted]]
2012 Jul 20
6
Speeding up a loop
General problem: I have 20 projects that can be invested in and I need to decide which combinations meet a certain set of standards. The total possible combinations comes out to 2^20. However I know for a fact that the number of projects must be greater than 5 and less than 13. So far the the code below is the best I can come up with for iteratively creating a set to check against my set of
2013 Sep 27
3
Compare species presence and absence between sites
Dear List, I want to compare the presence and absence of bird species based on the sites in a matrix. The matrix has 5 rows for Island A, B, C, D, and E. It has 100 columns for bird species D001-D100. In each cell of the matrix, the presence-absence of bird species will be recorded as 1 or 0. (For example, if species D001 is found on Island D, the matrix cell of species D001 and Island D
2017 Jun 23
1
R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames
Hello, Another way would be n <- nrow(expand.grid(1:nrow(D1), 1:nrow(D2))) D5 <- data.frame(distance=integer(n),difference=integer(n)) D5[] <- do.call(rbind, lapply(seq_len(nrow(D1)), function(i) t(sapply(seq_len(nrow(D2)), function(j){ c(distance=sqrt(sum((D1[i,1:2]-D2[j,1:2])^2)),difference=(D1[i,3]-D2[j,3])^2) } )))) identical(D3, D5) In my first answer I forgot to say that
2020 Feb 04
2
Stroring and extracting AICs from an ARIMA model using a nested loop
I am nowaware that I should not post this type of questions on this group. However, Iwould like to have some clarifications related to the response you've?alreadyprovided. The code you provided yields accurate results, however I still haveissues grasping the loop process in case 1 & 2. In case1,?the use of?"p+1" and "q+1" is still blurry tome? Likewise "0L"
2018 Aug 05
0
Is this a bug in `[`?
This is Circle 8..1.13 of the R Inferno. On 05/08/2018 06:57, Rui Barradas wrote: > Thanks. > This is exactly the doubt I had. > > Rui Barradas > > ?s 05:26 de 05/08/2018, Kenny Bell escreveu: >> This should more clearly illustrate the issue: >> >> c(1, 2, 3, 4)[-seq_len(4)] >> #> numeric(0) >> c(1, 2, 3, 4)[-seq_len(3)] >> #> [1] 4
2018 May 26
0
Grouping by 3 variable and renaming groups
Hello, See if this is it: priceStore_Grps$StoreID <- paste("Store", seq_len(nrow(priceStore_Grps)), sep = "_") Hope this helps, Rui Barradas On 5/26/2018 2:03 PM, Jeff Reichman wrote: > ALCON > > > > I'm trying to figure out how to rename groups in a data frame after groups > by selected variabels. I am using the dplyr library to group my
2018 May 26
1
Grouping by 3 variable and renaming groups
Hello, Sorry, but I think my first answer is wrong. You probably want something along the lines of sp <- split(priceStore_Grps, priceStore_Grps$StorePC) res <- lapply(seq_along(sp), function(i){ sp[[i]]$StoreID <- paste("Store", i, sep = "_") sp[[i]] }) res <- do.call(rbind, res) row.names(res) <- NULL Hope this helps, Rui Barradas On 5/26/2018
2012 Jul 07
11
Splitting a character vector.
I am lousy at simple regex and I have not found a solution to a simple problem. I have a vector with some character values that I want to split. Sample data dd1 <- c( "XXY (mat harry)","XXY (jim bob)", "CAMP (joe blow)", "ALP (max jack)") Desired result dd2 <- data.frame( xx = c("XXY", "XXY", "CAMP",
2017 Oct 14
2
Populate one data frame with values from another dataframe for rows that match
Dear @Rui Barradas, thank you for the solution. It works perfectly. On 13/10/2017, 23:35, "Rui Barradas" <ruipbarradas at sapo.pt> wrote: Hello, Try the following. myDF1$studyno <- as.character(myDF1$studyno) myDF2$studyno <- as.character(myDF2$studyno) i1 <- which(names(myDF1) == "pf_mcl") merge(myDF1[-i1], myDF2,
2018 Aug 05
0
Is this a bug in `[`?
This should more clearly illustrate the issue: c(1, 2, 3, 4)[-seq_len(4)] #> numeric(0) c(1, 2, 3, 4)[-seq_len(3)] #> [1] 4 c(1, 2, 3, 4)[-seq_len(2)] #> [1] 3 4 c(1, 2, 3, 4)[-seq_len(1)] #> [1] 2 3 4 c(1, 2, 3, 4)[-seq_len(0)] #> numeric(0) Created on 2018-08-05 by the reprex package (v0.2.0.9000). On Sun, Aug 5, 2018 at 3:58 AM Rui Barradas <ruipbarradas at sapo.pt>
2020 Feb 03
2
Stroring and extracting AICs from an ARIMA model using a nested loop
It works!!! Thank you so much for your help! Sent from my iPhone > On Feb 3, 2020, at 3:47 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote: > > ?Hello, > > You can solve the problem in two different ways. > > 1. Redefine storage1 as a matrix and extract the aic *in* the loop. > > storage1 <- matrix(0, 4, 4) > for(p in 0:3){ > for(q in 0:3){ >
2018 Aug 29
0
Is this a bug in `[`?
FYI, this behavior is documented in Section 3.4.1 'Indexing by vectors' of 'R Language Definition' (accessible for instance via help.start()): "*Integer* [...] A special case is the zero index, which has null effects: x[0] is an empty vector and otherwise including zeros among positive or negative indices has the same effect as if they were omitted." The rest of that
2020 Feb 03
3
Stroring and extracting AICs from an ARIMA model using a nested loop
Hello I am trying to extract AICs from an ARIMA estimation with different combinations of p & q ( p =0,1,2,3 and q=0,1.2,3). I have tried using the following code unsucessfully. Can anyone help? code: storage1 <- numeric(16) for (p in 0:3){ ? ? for (q in 0:3){ ? ? ? storage1[p]? <- arima(x,order=c(p,0,q), method="ML")} } storage1$aic [[alternative HTML version deleted]]
2017 Oct 14
0
Populate one data frame with values from another dataframe for rows that match
Hi Kevin, I think there are issues with Rui's proposed solution. For example, if there are rows in myDF1 which have a studyno which does not match any row in myDF2, then you will lose those rows. In your original request you said that you wanted to keep those rows. To demonstrate my point I need to modify your sample data. Specifically, I changed some studyno settings in myDF1, and also the