[問題] 不使用迴圈的方法
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
請把以下不需要的部份刪除
一個月新手(沒寫過程式,R 是我的第一次)
[問題敘述]:
我想要不使用for 以向量來改寫
[程式範例]:
背景
library(ncdf4)
input_nc <- nc_open("C:/buq/sechiba_history_sample.nc")
#data是一個list,內含的list又包了小list,包很多層
result<- list() #做一個空的list
for (i in 1:input_nc$ndims ) {
result[[input_nc$dim[[i]]$name]] <- input_nc$dim[[i]]$vals
# 同時建立內部的子list的名字和值 <- input_nc$dim$y$vals
}
以上是別人的成功寫法
================================================
以下 我想要不使用for 以向量來改寫
i<- (1:input_nc$ndims)
result[[input_nc$dim[[i]]$name]] <- input_nc$dim[[i]]$vals
錯誤碼如下
Error in input_nc$dim[[i]] : recursive indexing failed at level 3
[環境敘述]:
R version 3.3.3 (2017-03-06)
[關鍵字]:
批次 賦值 for
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.248.91.216
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1491618984.A.B3F.html
※ 編輯: BUQ (111.248.91.216), 04/08/2017 10:37:13
→
04/08 12:43, , 1F
04/08 12:43, 1F
→
04/08 22:25, , 2F
04/08 22:25, 2F
→
04/08 22:26, , 3F
04/08 22:26, 3F
→
04/08 22:52, , 4F
04/08 22:52, 4F
→
04/08 22:52, , 5F
04/08 22:52, 5F
→
04/08 22:52, , 6F
04/08 22:52, 6F
→
04/08 22:53, , 7F
04/08 22:53, 7F
→ BUQ: 我貼這兩行lapply 這種簡單範例 我懂...可是大大的組合技就.. → andrew43: x <- list(1:10, exp(-3:3)) 04/08 22:57
→
04/08 22:58, , 8F
04/08 22:58, 8F
→
04/08 23:16, , 9F
04/08 23:16, 9F
→
04/08 23:17, , 10F
04/08 23:17, 10F
→
04/08 23:18, , 11F
04/08 23:18, 11F
→
04/08 23:19, , 12F
04/08 23:19, 12F
→
04/08 23:23, , 13F
04/08 23:23, 13F
→
04/08 23:23, , 14F
04/08 23:23, 14F
→
04/08 23:24, , 15F
04/08 23:24, 15F
→
04/08 23:24, , 16F
04/08 23:24, 16F
→
04/08 23:24, , 17F
04/08 23:24, 17F
→
04/08 23:25, , 18F
04/08 23:25, 18F
→
04/08 23:26, , 19F
04/08 23:26, 19F
→
04/08 23:27, , 20F
04/08 23:27, 20F
→
04/08 23:28, , 21F
04/08 23:28, 21F
→
04/08 23:33, , 22F
04/08 23:33, 22F
→
04/08 23:33, , 23F
04/08 23:33, 23F
→
04/08 23:33, , 24F
04/08 23:33, 24F
→
04/08 23:34, , 25F
04/08 23:34, 25F
→
04/08 23:55, , 26F
04/08 23:55, 26F
→
04/09 00:02, , 27F
04/09 00:02, 27F
→
04/08 22:57, , 28F
04/08 22:57, 28F
→
04/08 22:58, , 29F
04/08 22:58, 29F
→
04/08 23:16, , 30F
04/08 23:16, 30F
→
04/08 23:17, , 31F
04/08 23:17, 31F
→
04/08 23:18, , 32F
04/08 23:18, 32F
→
04/08 23:19, , 33F
04/08 23:19, 33F
→
04/08 23:23, , 34F
04/08 23:23, 34F
→
04/08 23:23, , 35F
04/08 23:23, 35F
→
04/08 23:24, , 36F
04/08 23:24, 36F
→
04/08 23:24, , 37F
04/08 23:24, 37F
→
04/08 23:24, , 38F
04/08 23:24, 38F
→
04/08 23:25, , 39F
04/08 23:25, 39F
→
04/08 23:26, , 40F
04/08 23:26, 40F
→
04/08 23:27, , 41F
04/08 23:27, 41F
→
04/08 23:28, , 42F
04/08 23:28, 42F
→
04/08 23:33, , 43F
04/08 23:33, 43F
→
04/08 23:33, , 44F
04/08 23:33, 44F
→
04/08 23:33, , 45F
04/08 23:33, 45F
→
04/08 23:34, , 46F
04/08 23:34, 46F
→
04/08 23:55, , 47F
04/08 23:55, 47F
→
04/09 00:02, , 48F
04/09 00:02, 48F
※ 編輯: BUQ (175.96.65.181), 04/09/2017 00:05:45
→
04/09 00:19, , 49F
04/09 00:19, 49F
→
04/09 00:19, , 50F
04/09 00:19, 50F
→
04/09 00:19, , 51F
04/09 00:19, 51F
→
04/09 00:22, , 52F
04/09 00:22, 52F
→
04/09 00:30, , 53F
04/09 00:30, 53F
→
04/09 11:19, , 54F
04/09 11:19, 54F
→
04/11 11:07, , 55F
04/11 11:07, 55F
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章