ラベル locale の投稿を表示しています。 すべての投稿を表示
ラベル locale の投稿を表示しています。 すべての投稿を表示

2018年7月17日火曜日

Manipulate timezone



#
# prepare data according to system timezone. "Asia/Tokyo" in most cases.
#
bp.day <- merge(as.xts(as.vector(bp.xts[,1]),as.Date(index(bp.xts),tz=tzone(bp.xts))),as.vector(bp.xts[,2]))
colnames(bp.day)[1] <- "high"
colnames(bp.day)[2] <- "low"
#
# prepare timezone 2 hours behind "Asia/Tokyo".
#
bp.bangkok <- merge(as.xts(as.vector(bp.xts[,1]),as.Date(index(bp.xts),tz="Asia/Bangkok")),as.vector(bp.xts[,2]))
colnames(bp.bangkok)[1] <- "high"
colnames(bp.bangkok)[2] <- "low"
apply.weekly(bp.bangkok,mean)


  • Set timezone to other than Tokyo, as blood pressure may be measured after the mid night.
  • Setting time zone as "Bangkok" allows samples taken from 00:00 to 02:00 to be taken into the day before.

2016年6月10日金曜日

Calculate day dependent data with less workload - 1 set languge locale


In order to calculate day dependent data with less workload, I like to automate processes. The first step is to judge the first day of each belongs to which day of the week. weekday function provides this function.

Currently R's language setting is set to JA. This may be

weekdays(as.Date("2016-01-01"),abbreviate = TRUE)
[1] "金"
> Sys.getlocale("LC_MESSAGES")
[1] "ja_JP.UTF-8"

Change LC_MESSAGES to US. But weekdays function still return the value in Japanese.

> Sys.setlocale("LC_MESSAGES",'en_US')
[1] "en_US"
> weekdays(as.Date("2016-01-01"),abbreviate = TRUE)
[1] "金"

Investigate Sys.setlocale and found that there are other classes than LC_MESSAGES. I have no problem with US English.

> Sys.setlocale
function (category = "LC_ALL", locale = "") 
{
    category <- match(category, c("LC_ALL", "LC_COLLATE", "LC_CTYPE", 
        "LC_MONETARY", "LC_NUMERIC", "LC_TIME", "LC_MESSAGES", 
        "LC_PAPER", "LC_MEASUREMENT"))
    if (is.na(category)) 
        stop("invalid 'category' argument")
    .Internal(Sys.setlocale(category, locale))
}
<bytecode: 0x102cfdee0>
<environment: namespace:base>

Set LC_ALL locale, instead of LC_MESSAGES to US English.

> Sys.setlocale("LC_ALL",'en_US')
[1] "en_US/en_US/en_US/C/en_US/en_US"

Then return is in US English.

> weekdays(as.Date("2016-01-01"),abbreviate = TRUE)
[1] "Fri"
>