У меня есть доходность 108 паевых инвестиционных фондов и более за период с 1987 по 2019 год. Я хочу подсчитать общее количество наблюдений (исключая NA) за существование фондов.
Мне удалось получить эксцесс, асимметрию и т. Д. c, используя следующие коды:
kurt <- apply(funds, 2, kurtosis, na.rm = TRUE)
skew <- apply(funds, 2, skewness, na.rm = TRUE)
max <- apply(funds, 2, max, na.rm = TRUE)
min <- apply(funds, 2, min, na.rm = TRUE)
sd <- apply(funds, 2, sd, na.rm = TRUE)
m <- apply(funds, 2, mean, na.rm = TRUE)
Затем попытка сделать то же самое с количеством наблюдений и безуспешно:
obs <- apply(funds, 2, count, na.rm = TRUE)
Получение этой ошибки: Ошибка в UseMethod ("group_by_"): нет применимого метода для 'group_by_', примененного к объекту класса "c ('double', 'numeri c ') "
Первые 10 строк из набора данных здесь (средства). Он намного длиннее, но должен быть достаточно наглядным. Как видите, в первых строках много NA. Количество наблюдений здесь будет равно 0, а если посмотреть на фонд «DK.NORGE», количество наблюдений в первых 10 строках будет 10.
structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, -0.0090002245623988, 0.00232763847063611,
0.0666744669374286, 0.0541982646590207, 0.0357777115456177, 0.0112375620619904,
0.0517733147448458, 0.0553272554088993, 0.0964919466161833, -0.183504972082187,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, -0.0132758821474321, 0.0246370824973443,
0.0436835891381346, 0.0356472795497187, 0.000293052003410121,
-0.0158201720510295, 0.0677617514139583, 0.0710647033479483,
0.0996190340976313, -0.26700522906759, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, 0.0609178826615828, 0.0330911715918167,
0.0246199591154059, 0.0387559218497211, -0.0219724959665873,
0.00576292730999128, 0.0607497869923317, 0.0968700634555142,
0.118662582078258, -0.149187455335955, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, -0.00338009126246408,
0.0625741902662371, -0.0197095435684648, 0.0235653235653237,
-0.0205574774344905, 0.0211513478402079, 0.0440504114817319,
0.0713605727123872, 0.122338724009241, -0.193811951737024, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 0.0182819486204802, 0.052568368712947,
0.0223478709564888, 0.0430931528662419, 0.00418444259680784,
0.0149102804245731, 0.0891504229496138, 0.101929676995524, 0.0713342508037151,
-0.184479046400599, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA), .Dim = c(10L, 108L), .Dimnames = list(
NULL, c("AI.NORS2", "AI.AKSJN", "AB.AKSPR", "AI.AKTIV", "GA.KAPIT",
"GA.GAMB", "BF.HUMAN", "AB.NOPEN", "VL.AKNOR", "AI.NORGS",
"AI.NORG", "BF.NORGE", "AI.NORGI", "AI.VEKST", "AC.NWECA",
"AC.NEQCB", "AC.NWECD", "AC.NWECI", "NR.NORGE", "BF.NORG",
"CA.AKSJE", "CL.AKNOR", "FF.AKFOR", "FF.NOIII", "FF.NOAI2",
"FF.NORGE", "FF.NORII", "FF.VEKST", "DF.NORGE", "DF.VEKST",
"DK.PBNOR", "DK.NORGE", "DK.NORII", "DI.RINV", "DK.NORG3",
"DK.NORIV", "DK.NOIVR", "DK.NSEL1", "DK.NSEL2", "DK.NSEL3",
"DI.RVKST", "DI.SMB", "EK.NORGE", "NF.PLUSS", "FT.GNRTR",
"FT.NOFOK", "FF.BARNE", "FK.AKTI2", "FK.SPAR", "FV.NORGE",
"FV.TRNDR", "GA.OPPKJ", "GF.AKSJE", "GF.INVES", "SU.AKTIV",
"SU.GLNO", "SU.NORGE", "HF.NORGE", "HB.HNORG", "HO.NORGE",
"KF.IPA", "KL.AKSJE", "KL.AKSNO", "IS.NORGE", "IS.UTBYT",
"IS.UTBYI", "NF.AKSJE", "KF.AVKAS", "KF.BARNE", "KF.KAP",
"KF.KAPIT", "KF.KAIII", "KF.NOPLS", "KF.AKPEN", "KF.SMB",
"KF.SMBII", "KF.VEKST", "OD.NORGE", "OD.NORGA", "OD.NORGB",
"OD.NORGD", "OD.NORII", "OR.FIN30", "PO.AKTIV", "FO.AKSJE",
"FO.INDX", "PV.VEKST", "NF.RFAKS", "NF.RFPLU", "AI.SKAFS",
"SE.NORGE", "SK.HORIS", "SK.SMB", "SR.NORGA", "SR.NORGB",
"SP.INNLA", "SP.AKSJS", "SP.NORGE", "SP.NORGA", "SP.STNOP",
"SP.NORGI", "SP.NOINS", "SP.OPTIM", "SP.VEKST", "SP.VERDI",
"SP.STVEN", "TF.NORGE", "OD.VÅRAK")))
Любая обратная связь приветствуется. Спасибо.