新手R用戶在這裏。所以我有一個數據集格式化,如:索引矩陣R
Date Temp Month
1-Jan-90 10.56 1
2-Jan-90 11.11 1
3-Jan-90 10.56 1
4-Jan-90 -1.67 1
5-Jan-90 0.56 1
6-Jan-90 10.56 1
7-Jan-90 12.78 1
8-Jan-90 -1.11 1
9-Jan-90 4.44 1
10-Jan-90 10.00 1
在該R語法:
datacl <- structure(list(Date = structure(1:10, .Label = c("1990/01/01",
"1990/01/02", "1990/01/03", "1990/01/04", "1990/01/05", "1990/01/06",
"1990/01/07", "1990/01/08", "1990/01/09", "1990/01/10"), class = "factor"),
Temp = c(10.56, 11.11, 10.56, -1.67, 0.56, 10.56, 12.78,
-1.11, 4.44, 10), Month = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L)), .Names = c("Date", "Temp", "Month"), class = "data.frame", row.names = c(NA,
-10L))
我想子集數據的特定月份和申請變更率到temp然後保存結果。所以我有這樣的事情
idx <- subset(datacl, Month == 1) # Index
results[idx[,2],1] = idx[,2]+change # change applied to only index values
,但我不斷收到這樣的錯誤
Error in results[idx[, 2], 1] = idx[, 2] + change:
only 0's may be mixed with negative subscripts
任何幫助,將不勝感激。
謝謝!正是我想要的。 – user1408959