私は小さなデータセットを持っており、grepl関数を使ってdata.frameをサブセット化しようとしています。以下をループ関数に変換してください。
私は持っています。
year_list <- list("2013", "2014", "2015", "2016", "2017")
test.2013 <- subset(searches[, 1:2], grepl(year_list[1], searches$date))
test.2014 <- subset(searches[, 1:2], grepl(year_list[2], searches$date))
test.2015 <- subset(searches[, 1:2], grepl(year_list[3], searches$date))
test.2016 <- subset(searches[, 1:2], grepl(year_list[4], searches$date))
test.2017 <- subset(searches[, 1:2], grepl(year_list[5], searches$date))
私は新しいdata.frame
に、列1(date
列とhits
列)2のサブセットにするためにループを作成しようとしています。
私は、year_lists
でdate
を取るsearches data.frame
の列date
にgrepl関数を適用し、新しいdata.frame
にこれらの値を返すようにしようとしているが、ループ機能や、私が現在持っているものよりも少ない繰り返し何かを使用しています。
DATAFRAME
date hits keyword geo gprop category
1: 2013-01-06 23 Price world web 0
2: 2013-01-13 23 Price world web 0
3: 2013-01-20 40 Price world web 0
4: 2013-01-27 25 Price world web 0
5: 2013-02-03 21 Price world web 0
6: 2013-02-10 19 Price world web 0
あなたはdata.tableオブジェクトを使用しています。 – jogo
'library(" lubridate "); 検索[、年:=年(as.Date(date))]今度は 'split(searches、searches [、Year])'を実行できます。 = 'あなたのさらなる計算のための' data.table'のパラメータ。 – jogo