Re: [R] about opening R script Chinese annotation garble problem

2022-04-25 Thread Bill Dunlap
The answer depends on the encoding of the file containing the Chinese characters and on the version of R (since you are using Windows). I copied your subject line into Wordpad and and added some syntax to make a valid R expression s <- "永创 via R-help" I then saved it with the type "Unicode Text

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Rui Barradas
Hello, If !!x obfuscates what the is doing, there's M[, as.logical(x)] <- 0 Hope this helps, Rui Barradas Às 15:52 de 25/04/2022, Ivan Calandra escreveu: Indeed, of course, my bad! I got confused by Bert's answer... So my first suggestion to do M[, x == 1] was correct :) -- Dr. Ivan

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Bert Gunter
Oh, I get it. The context was in choosing columns to set to 0 via a **predicate**. Sorry for the noise. Bert On Mon, Apr 25, 2022 at 7:39 AM Bert Gunter wrote: > > Yes, sorry. But it's with the logical cast it's still M[, c(FALSE, > TRUE, FALSE)] which is M[, 2], and so I still don't get the

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Bert Gunter
Yes, sorry. But it's with the logical cast it's still M[, c(FALSE, TRUE, FALSE)] which is M[, 2], and so I still don't get the point. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Ivan Calandra
Indeed, M[, x] <- 0 does the same, but only if x is 0's and 1's only, right? I thought that it might not always be the case so I choose this maybe superflous approach. M[, 2] does the same of course in the example, but I was assuming that the columns to change to zero are not known in advance

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Eric Berger
M[,x==1] is not the same as M[,x] :-) However, M[,!!x] is the same as M[,x==1] and saves one character! The point of this is "I can name that tune in ... " (as if that was not obvious) On Mon, Apr 25, 2022 at 5:30 PM Bert Gunter wrote: > x == 1 is the same as M[, x] so your expression is the

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Bert Gunter
x == 1 is the same as M[, x] so your expression is the same as M[, c(FALSE, TRUE, FALSE)] <- 0 which is the same as M[, 2] <- 0 So what is the point of all this, exactly? Bert On Mon, Apr 25, 2022 at 7:18 AM Ivan Calandra wrote: > > Hi Uwe, > > If I understood the problem completely and

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Ivan Calandra
Hi Uwe, If I understood the problem completely and building up on Tim's answer, this is even easier: M <- A <- matrix(1:9, ncol = 3) x <- c(0, 1, 0) M[, x == 1] <- 0 M The original issue was with the way ifelse works. The explanation is in the help page: "ifelse returns a value with the same

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Ebert,Timothy Aaron
A <- matrix(1:9,ncol=3) x <- c(0,1,0) M <- matrix(ncol=3,nrow=3) M<-A for(i in 1:3) { if(x[i]){ M[,i] <-0 } } } M The outcome you want is to set all of the middle column values to zero. So I used x as a logical in an if test and when true everything in that column is set to zero.

Re: [R] conversion of d m s (lat) d m s (long) coordinates into decimal coordinates

2022-04-25 Thread Rui Barradas
Hello, Here is the link to the archived versions of package measurements [1]. But the edit to that answer has another solution, with sp::char2dms and you are loading package sp. [1] https://cran.hafro.is/src/contrib/Archive/measurements/ Hope this helps, Rui Barradas Às 10:57 de

Re: [R] conversion of d m s (lat) d m s (long) coordinates into decimal coordinates

2022-04-25 Thread Rui Barradas
Hello, See if this StackOverflow.com post [1] solves your problem. Also, examples should be minimal, you don't need all those packages to solve this problem. [1] https://stackoverflow.com/a/69485865/8245406 Hope this helps, Rui Barradas Às 21:43 de 24/04/2022, Nicolas Degallier

Re: [R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Ivan Krylov
В Sun, 24 Apr 2022 17:05:55 +0200 Uwe Freier пишет: > ifelse(x[i] == 0, A[,i], 0) Hint: what does ifelse return instead of a vector of length nrow(A)? Since you're checking conditions of length 1, you can safely use `if (x[i] == 0) A[,i] else 0` here, or you can transform the `x` vector into a

[R] Confusing fori or ifelse result in matrix manipulation

2022-04-25 Thread Uwe Freier
Hello, sorry for the newbie question but I can't find out where I'm wrong. A <- matrix(1:9,ncol=3) x <- c(0,1,0) M <- matrix(ncol=3,nrow=3) for(i in 1:3) { M[,i] <- ifelse(x[i] == 0, A[,i], 0) } expected: M [,1] [,2] [,3] [1,]107 [2,]208 [3,]309

[R] conversion of d m s (lat) d m s (long) coordinates into decimal coordinates

2022-04-25 Thread Nicolas Degallier
Dear R Users, I am using a 'simple' script to draw maps with points. It runs fine with the following libraries: library(sp) library(maptools) library(maps) library(mapdata) library(RColorBrewer) library(MASS) library(rgeos) library(GISTools) Until now, to prepare the input data, I have used