R function not writing matrix with col indexing
I am trying to map values from a stochastic process. While in the past the following code produced a correct matrix with number_draws
rows, it is not not working and giving me the following error:
Error in X[, i] <- Marginals_Beta_Var[U[, i], i] :
incorrect number of subscripts on matrix
as well as turning X into a huge matrix with 10000x10000 dimension. Code:
number_draws = 10000
X = matrix(nrow = number_draws, ncol = 18)
for (i in 1:18){
X[,i] = Marginals_Beta_Var[U[, i], i]
}
The Matrix U has indices for columns for mapping to other marginals
> head(U)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16]
[1,] 30 2 164 486 30 362 317 81 431 197 408 139 106 500 398 199
[2,] 275 40 217 173 172 366 218 205 96 255 184 255 38 328 375 175
[3,] 169 117 407 112 343 38 88 406 266 77 69 483 40 303 136 236
[4,] 245 261 54 364 287 224 320 246 446 71 340 7 250 360 341 75
[5,] 332 356 197 194 248 268 108 133 429 409 121 472 418 473 289 121
[6,] 328 60 160 310 181 411 183 499 339 350 354 28 104 278 444 210
[,17] [,18]
[1,] 98 197
[2,] 469 205
[3,] 117 23
[4,] 39 457
[5,] 362 359
[6,] 329 304
Marginals_Beta_Var has 500 rows and 18 columns, each with a different value.
The code has previously worked. I am calling this within a function, perhaps I messed up the global values.
Thank you for your help.
r function
add a comment |
I am trying to map values from a stochastic process. While in the past the following code produced a correct matrix with number_draws
rows, it is not not working and giving me the following error:
Error in X[, i] <- Marginals_Beta_Var[U[, i], i] :
incorrect number of subscripts on matrix
as well as turning X into a huge matrix with 10000x10000 dimension. Code:
number_draws = 10000
X = matrix(nrow = number_draws, ncol = 18)
for (i in 1:18){
X[,i] = Marginals_Beta_Var[U[, i], i]
}
The Matrix U has indices for columns for mapping to other marginals
> head(U)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16]
[1,] 30 2 164 486 30 362 317 81 431 197 408 139 106 500 398 199
[2,] 275 40 217 173 172 366 218 205 96 255 184 255 38 328 375 175
[3,] 169 117 407 112 343 38 88 406 266 77 69 483 40 303 136 236
[4,] 245 261 54 364 287 224 320 246 446 71 340 7 250 360 341 75
[5,] 332 356 197 194 248 268 108 133 429 409 121 472 418 473 289 121
[6,] 328 60 160 310 181 411 183 499 339 350 354 28 104 278 444 210
[,17] [,18]
[1,] 98 197
[2,] 469 205
[3,] 117 23
[4,] 39 457
[5,] 362 359
[6,] 329 304
Marginals_Beta_Var has 500 rows and 18 columns, each with a different value.
The code has previously worked. I am calling this within a function, perhaps I messed up the global values.
Thank you for your help.
r function
I'm assuming the type in "number_draws" (says "numbe_draws" instead) in your example here doesn't occur in your actual code?
– iod
Nov 26 '18 at 3:29
Yes, you are right. The Marginals_Beta_Var[U[, i], i] is apparantly a tibble, could that be the problem?
– IschaIschratioh
Nov 26 '18 at 3:40
add a comment |
I am trying to map values from a stochastic process. While in the past the following code produced a correct matrix with number_draws
rows, it is not not working and giving me the following error:
Error in X[, i] <- Marginals_Beta_Var[U[, i], i] :
incorrect number of subscripts on matrix
as well as turning X into a huge matrix with 10000x10000 dimension. Code:
number_draws = 10000
X = matrix(nrow = number_draws, ncol = 18)
for (i in 1:18){
X[,i] = Marginals_Beta_Var[U[, i], i]
}
The Matrix U has indices for columns for mapping to other marginals
> head(U)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16]
[1,] 30 2 164 486 30 362 317 81 431 197 408 139 106 500 398 199
[2,] 275 40 217 173 172 366 218 205 96 255 184 255 38 328 375 175
[3,] 169 117 407 112 343 38 88 406 266 77 69 483 40 303 136 236
[4,] 245 261 54 364 287 224 320 246 446 71 340 7 250 360 341 75
[5,] 332 356 197 194 248 268 108 133 429 409 121 472 418 473 289 121
[6,] 328 60 160 310 181 411 183 499 339 350 354 28 104 278 444 210
[,17] [,18]
[1,] 98 197
[2,] 469 205
[3,] 117 23
[4,] 39 457
[5,] 362 359
[6,] 329 304
Marginals_Beta_Var has 500 rows and 18 columns, each with a different value.
The code has previously worked. I am calling this within a function, perhaps I messed up the global values.
Thank you for your help.
r function
I am trying to map values from a stochastic process. While in the past the following code produced a correct matrix with number_draws
rows, it is not not working and giving me the following error:
Error in X[, i] <- Marginals_Beta_Var[U[, i], i] :
incorrect number of subscripts on matrix
as well as turning X into a huge matrix with 10000x10000 dimension. Code:
number_draws = 10000
X = matrix(nrow = number_draws, ncol = 18)
for (i in 1:18){
X[,i] = Marginals_Beta_Var[U[, i], i]
}
The Matrix U has indices for columns for mapping to other marginals
> head(U)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16]
[1,] 30 2 164 486 30 362 317 81 431 197 408 139 106 500 398 199
[2,] 275 40 217 173 172 366 218 205 96 255 184 255 38 328 375 175
[3,] 169 117 407 112 343 38 88 406 266 77 69 483 40 303 136 236
[4,] 245 261 54 364 287 224 320 246 446 71 340 7 250 360 341 75
[5,] 332 356 197 194 248 268 108 133 429 409 121 472 418 473 289 121
[6,] 328 60 160 310 181 411 183 499 339 350 354 28 104 278 444 210
[,17] [,18]
[1,] 98 197
[2,] 469 205
[3,] 117 23
[4,] 39 457
[5,] 362 359
[6,] 329 304
Marginals_Beta_Var has 500 rows and 18 columns, each with a different value.
The code has previously worked. I am calling this within a function, perhaps I messed up the global values.
Thank you for your help.
r function
r function
edited Nov 26 '18 at 3:41
IschaIschratioh
asked Nov 26 '18 at 3:21
IschaIschratiohIschaIschratioh
648
648
I'm assuming the type in "number_draws" (says "numbe_draws" instead) in your example here doesn't occur in your actual code?
– iod
Nov 26 '18 at 3:29
Yes, you are right. The Marginals_Beta_Var[U[, i], i] is apparantly a tibble, could that be the problem?
– IschaIschratioh
Nov 26 '18 at 3:40
add a comment |
I'm assuming the type in "number_draws" (says "numbe_draws" instead) in your example here doesn't occur in your actual code?
– iod
Nov 26 '18 at 3:29
Yes, you are right. The Marginals_Beta_Var[U[, i], i] is apparantly a tibble, could that be the problem?
– IschaIschratioh
Nov 26 '18 at 3:40
I'm assuming the type in "number_draws" (says "numbe_draws" instead) in your example here doesn't occur in your actual code?
– iod
Nov 26 '18 at 3:29
I'm assuming the type in "number_draws" (says "numbe_draws" instead) in your example here doesn't occur in your actual code?
– iod
Nov 26 '18 at 3:29
Yes, you are right. The Marginals_Beta_Var[U[, i], i] is apparantly a tibble, could that be the problem?
– IschaIschratioh
Nov 26 '18 at 3:40
Yes, you are right. The Marginals_Beta_Var[U[, i], i] is apparantly a tibble, could that be the problem?
– IschaIschratioh
Nov 26 '18 at 3:40
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474389%2fr-function-not-writing-matrix-with-col-indexing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474389%2fr-function-not-writing-matrix-with-col-indexing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm assuming the type in "number_draws" (says "numbe_draws" instead) in your example here doesn't occur in your actual code?
– iod
Nov 26 '18 at 3:29
Yes, you are right. The Marginals_Beta_Var[U[, i], i] is apparantly a tibble, could that be the problem?
– IschaIschratioh
Nov 26 '18 at 3:40