Re: [R] How to assign the same levels to a dataframe column?

2020-10-20 Thread Luigi Marongiu
Thanks, I will do that. On Tue, Oct 20, 2020 at 4:15 PM Jeff Newmiller wrote: > > Stop using as.factor() and start using factor()? Be explicit about what > levels you want and in what order. > > As for extracting subsets, use split() and do your subsets on each set of > rows with the same level

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Marc Schwartz via R-help
Hi, One additional option that you might want to look at is to use ?writeLines with 'useBytes = TRUE', where the default is FALSE. Windows, as Duncan notes, is problematic with extended encodings, and you can actually get conflicted encoding of text, based upon what is used within R, versus th

Re: [R] sp:gIntersection warning message about projection

2020-10-20 Thread Bert Gunter
Probably better asked on the r-sig-geo list, which is specifically for spatial statistics. 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 County" comic strip ) On Tue, Oct 20, 2020 at

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Jinsong Zhao
Thank you very much for the hint. I tried it on a FreeBSD machine with locale set to en_US.UTF-8, it works fine. However, on my Windows machine, > Sys.getlocale() [1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese (Simplified)_China.936;LC_MONETARY=Chinese (Simplified)_China.936;L

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Duncan Murdoch
You don't say, but I'd guess you're using Windows. In your code page, the character Å is probably not representable. At some point in the sequence of operations involved in printing the dataframe R puts the string into the native encoding, and since that's impossible on your system, it substi

Re: [R] How to assign the same levels to a dataframe column?

2020-10-20 Thread Jeff Newmiller
Stop using as.factor() and start using factor()? Be explicit about what levels you want and in what order. As for extracting subsets, use split() and do your subsets on each set of rows with the same level. It will be on you to decide what statistical properties (proportions?) you want to maint

Re: [R] write.csv covert Åland to land

2020-10-20 Thread John Kane
It looks like an encoding problem. It works fine for me with R encoding set to UTF-8 Here is part of my sessionInfo() results [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 I would suggest

[R] How to assign the same levels to a dataframe column?

2020-10-20 Thread Luigi Marongiu
Hello, I have a dataframe df with a column x that has these unique values: "L" "M" "V" "N" "H". I can assign a factor to it: ``` df$x = as.factor(df$x) > [1] L M V N H Levels: H L M N V ``` I now need to get a subset of this dataframe. I could do the same thing as before on the subset sf, but I wou

[R] sp:gIntersection warning message about projection

2020-10-20 Thread Robert Lovejoy
Hi, I am using in my workflow gIntersection from sp package. Part of my relevant sessionInfo is: R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 17763) attached base packages: [1] stats graphics grDevices utils datasets methods

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Jinsong Zhao
Hi there, Why the same string is displayed in different form? > abc[,1] [1] "Åland" "Afghanistan" > abc name 1land 2 Afghanistan And more... > dput(abc, "aa.txt") > dget("aa.txt") name 1land 2 Afghanistan > dget("aa.txt")[,1] [1] "land""Afghanistan" Best, J

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Dr Eberhard W Lisse
Perhaps ?readr::write_delim() el On 20/10/2020 12:45, Dr Eberhard W Lisse wrote: > Apologies, > > I meant > > ?write.table() > > el > > On 20/10/2020 12:38, Jinsong Zhao wrote: >> On 2020/10/20 17:23, Dr Eberhard W Lisse wrote: >>> ?file.write() >>> >>> look for fileEncoding? >>> >>> el >>>

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Dr Eberhard W Lisse
Apologies, I meant ?write.table() el On 20/10/2020 12:38, Jinsong Zhao wrote: > On 2020/10/20 17:23, Dr Eberhard W Lisse wrote: >> ?file.write() >> >> look for fileEncoding? >> >> el >> > > There is no file.write(). I have tried fileEncoding = "utf8" and > "latin1" in write.csv(). However,

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Jinsong Zhao
On 2020/10/20 17:23, Dr Eberhard W Lisse wrote: ?file.write() look for fileEncoding? el There is no file.write(). I have tried fileEncoding = "utf8" and "latin1" in write.csv(). However, it does not have effect. The output is is land or land. Best, Jinsong On 20/10/2020 11:13, Jinsong

Re: [R] write.csv covert Åland to land

2020-10-20 Thread Dr Eberhard W Lisse
?file.write() look for fileEncoding? el On 20/10/2020 11:13, Jinsong Zhao wrote: > Hi there, > > I tried to export the names of country to a csv file with write.csv(). In the > resulted file, Åland was coverted to land. Is there any way could prevent > this happening? Thanks! > >> abc > [1]

[R] write.csv covert Åland to land

2020-10-20 Thread Jinsong Zhao
Hi there, I tried to export the names of country to a csv file with write.csv(). In the resulted file, Åland was coverted to land. Is there any way could prevent this happening? Thanks! > abc [1] "Åland" > write.table(abc, file = "") "x" "1" "land" Best, Jinsong