如何将数据框中的年份值转换为2位数值?

时间:2016-08-12 23:44:09

标签: r

我已尝试使用此公式转换我的数据框中提到的年份" Yr"成2位数值

yr <- format((Yr[,]), format = "%y")

注意:Yr是一个data.frame,由年值组成。 2015年,2012年,1998年等。我试图将这些值分别加载到变量yr中,格式分别为15,12,98。

1 个答案:

答案 0 :(得分:3)

function playbackRecording(content) { var waitTime = 0; var keypress = content[0]; actionApp(keypress.key_pressed); for (var i = 1; i < content.length; i++) { waitTime += keypress.time_to_next_key; keypress = content[i]; var end = Date.now() + waitTime; while(Date.now() < end) {} actionApp(keypress.key_pressed); } } function playbackLinkClicked(evt) { var urlString = '/fetch_recording/' + this.id; $.get(urlString, function(data){ if (data.status === 'success') { playbackRecording(data.content); } else { alert('Could not load recording.'); } }); } $('.playback').click(playbackLinkClicked); 怎么样?

echo 'PR-1769|7bb12d4152a497cef491e0a1088b3984ad92972f|jaga|'|awk -F'|' '{print substr($1, 4)}'

另一种方法是使用sprintf("%02d", Year %% 100),由@alistaire评论:

Year <- 1960:2016
sprintf("%02d", Year %% 100)
# [1] "60" "61" "62" "63" "64" "65" "66" "67" "68" "69" "70" "71" "72" "73" "74"
#[16] "75" "76" "77" "78" "79" "80" "81" "82" "83" "84" "85" "86" "87" "88" "89"
#[31] "90" "91" "92" "93" "94" "95" "96" "97" "98" "99" "00" "01" "02" "03" "04"
#[46] "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15" "16"