Using FOR loop to fill in a data from in R (code review)
So my objective is to fill in the last column of a data frame with values. The data frame is [343,8]. I wrote up a solution to this but it is not working and I am curious as to why my idea would not work:
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i:j]
}
combos$prize[i] = score(result)
}
The name of the larger data frame is "combos", the last column of the data frame is "prize".
My attempt was to create the empty vector "result", fill it with the values from the first three columns of "combos", then apply a function that I created called "score" on to the "result" vector, and finally fill in the the specific entry in the "combo" data frame with the value obtained from "score".
My version doesn't work, but there is a solution in the textbook which works:
for (i in 1:nrow(combos)) {
symbols <- c(combos[i, 1], combos[i, 2], combos[i, 3])
combos$prize[i] <- score(symbols)
}
Now I don't see much difference between what the author did and myself. Yes he didn't use a second FOR loop, but the procedure to arrive at the final result seems consistent.
With that being said, what is it that I did not do correct?
EDIT This is a copy of the score function that I am calling in my for loop:
score = function(symbols) {
# identify case
same = symbols[1] == symbols[2] & symbols[2] == symbols[3]
bars = symbols %in% c("B","BB","BBB")
# get prize
if (same) {
payouts = c("DD" = 100, "7" = 80, "BBB" = 40, "BB" = 25, "B" = 10, "C" = 10,
"0" = 0)
prize = unname(payouts[symbols[1]])
} else if (all(bars)){
prize = 5
} else {
cherries = sum("C" == symbols)
prize = c(0,2,5)[cherries + 1]
}
# adjust for diamonds
diamonds = sum("DD" == symbols)
prize * 2 ^(diamonds)
}
r dataframe for-loop
add a comment |
So my objective is to fill in the last column of a data frame with values. The data frame is [343,8]. I wrote up a solution to this but it is not working and I am curious as to why my idea would not work:
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i:j]
}
combos$prize[i] = score(result)
}
The name of the larger data frame is "combos", the last column of the data frame is "prize".
My attempt was to create the empty vector "result", fill it with the values from the first three columns of "combos", then apply a function that I created called "score" on to the "result" vector, and finally fill in the the specific entry in the "combo" data frame with the value obtained from "score".
My version doesn't work, but there is a solution in the textbook which works:
for (i in 1:nrow(combos)) {
symbols <- c(combos[i, 1], combos[i, 2], combos[i, 3])
combos$prize[i] <- score(symbols)
}
Now I don't see much difference between what the author did and myself. Yes he didn't use a second FOR loop, but the procedure to arrive at the final result seems consistent.
With that being said, what is it that I did not do correct?
EDIT This is a copy of the score function that I am calling in my for loop:
score = function(symbols) {
# identify case
same = symbols[1] == symbols[2] & symbols[2] == symbols[3]
bars = symbols %in% c("B","BB","BBB")
# get prize
if (same) {
payouts = c("DD" = 100, "7" = 80, "BBB" = 40, "BB" = 25, "B" = 10, "C" = 10,
"0" = 0)
prize = unname(payouts[symbols[1]])
} else if (all(bars)){
prize = 5
} else {
cherries = sum("C" == symbols)
prize = c(0,2,5)[cherries + 1]
}
# adjust for diamonds
diamonds = sum("DD" == symbols)
prize * 2 ^(diamonds)
}
r dataframe for-loop
1
score
returns an integer value ?
– YOLO
Dec 28 '18 at 19:40
@yolo yes it does
– dc3rd
Dec 28 '18 at 19:49
add a comment |
So my objective is to fill in the last column of a data frame with values. The data frame is [343,8]. I wrote up a solution to this but it is not working and I am curious as to why my idea would not work:
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i:j]
}
combos$prize[i] = score(result)
}
The name of the larger data frame is "combos", the last column of the data frame is "prize".
My attempt was to create the empty vector "result", fill it with the values from the first three columns of "combos", then apply a function that I created called "score" on to the "result" vector, and finally fill in the the specific entry in the "combo" data frame with the value obtained from "score".
My version doesn't work, but there is a solution in the textbook which works:
for (i in 1:nrow(combos)) {
symbols <- c(combos[i, 1], combos[i, 2], combos[i, 3])
combos$prize[i] <- score(symbols)
}
Now I don't see much difference between what the author did and myself. Yes he didn't use a second FOR loop, but the procedure to arrive at the final result seems consistent.
With that being said, what is it that I did not do correct?
EDIT This is a copy of the score function that I am calling in my for loop:
score = function(symbols) {
# identify case
same = symbols[1] == symbols[2] & symbols[2] == symbols[3]
bars = symbols %in% c("B","BB","BBB")
# get prize
if (same) {
payouts = c("DD" = 100, "7" = 80, "BBB" = 40, "BB" = 25, "B" = 10, "C" = 10,
"0" = 0)
prize = unname(payouts[symbols[1]])
} else if (all(bars)){
prize = 5
} else {
cherries = sum("C" == symbols)
prize = c(0,2,5)[cherries + 1]
}
# adjust for diamonds
diamonds = sum("DD" == symbols)
prize * 2 ^(diamonds)
}
r dataframe for-loop
So my objective is to fill in the last column of a data frame with values. The data frame is [343,8]. I wrote up a solution to this but it is not working and I am curious as to why my idea would not work:
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i:j]
}
combos$prize[i] = score(result)
}
The name of the larger data frame is "combos", the last column of the data frame is "prize".
My attempt was to create the empty vector "result", fill it with the values from the first three columns of "combos", then apply a function that I created called "score" on to the "result" vector, and finally fill in the the specific entry in the "combo" data frame with the value obtained from "score".
My version doesn't work, but there is a solution in the textbook which works:
for (i in 1:nrow(combos)) {
symbols <- c(combos[i, 1], combos[i, 2], combos[i, 3])
combos$prize[i] <- score(symbols)
}
Now I don't see much difference between what the author did and myself. Yes he didn't use a second FOR loop, but the procedure to arrive at the final result seems consistent.
With that being said, what is it that I did not do correct?
EDIT This is a copy of the score function that I am calling in my for loop:
score = function(symbols) {
# identify case
same = symbols[1] == symbols[2] & symbols[2] == symbols[3]
bars = symbols %in% c("B","BB","BBB")
# get prize
if (same) {
payouts = c("DD" = 100, "7" = 80, "BBB" = 40, "BB" = 25, "B" = 10, "C" = 10,
"0" = 0)
prize = unname(payouts[symbols[1]])
} else if (all(bars)){
prize = 5
} else {
cherries = sum("C" == symbols)
prize = c(0,2,5)[cherries + 1]
}
# adjust for diamonds
diamonds = sum("DD" == symbols)
prize * 2 ^(diamonds)
}
r dataframe for-loop
r dataframe for-loop
edited Dec 28 '18 at 20:23
dc3rd
asked Dec 28 '18 at 19:34
dc3rddc3rd
1027
1027
1
score
returns an integer value ?
– YOLO
Dec 28 '18 at 19:40
@yolo yes it does
– dc3rd
Dec 28 '18 at 19:49
add a comment |
1
score
returns an integer value ?
– YOLO
Dec 28 '18 at 19:40
@yolo yes it does
– dc3rd
Dec 28 '18 at 19:49
1
1
score
returns an integer value ?– YOLO
Dec 28 '18 at 19:40
score
returns an integer value ?– YOLO
Dec 28 '18 at 19:40
@yolo yes it does
– dc3rd
Dec 28 '18 at 19:49
@yolo yes it does
– dc3rd
Dec 28 '18 at 19:49
add a comment |
2 Answers
2
active
oldest
votes
So your issue is with how you are creating your symbols "vector". Because a data.frame is really considered a type of "list" in R, what you are doing is assigning a 3-element list to your symbols variable. Hence, you will need to unlist this before you can make the comparisons you are seeking.
for (i in 1:nrow(combos)) {
symbols <- unlist(c(combos[i, 1], combos[i, 2], combos[i, 3]))
combos$prize[i] <- score(symbols)
}
This should solve your issue though I cannot exactly test without the combos data.frame but I assume this is your issue just looking at the code and the error message you received. Good luck!
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
add a comment |
Note that i:j
in combos[i:j]
returns a vector from i to j. Try to run 5:7
for example. So you're doing some 'weird' subsetting with combos[i:j]
. You probably want that to be combos[i, j]
which returns the (i, j)th entry of combos.
combos[i:j]
returns the i'th through j'th entries of combos
(which I assume is a numeric matrix). In R, matrices are stored in a column-major order, so the your intial subsetting returns the corresponding entries and might 'span the columns'. Take a look a the following to illustrate:
x <- matrix(1:6, 2, 3)
print(x)
# [,1] [,2] [,3]
#[1,] 1 3 5
#[2,] 2 4 6
print(x[2:3])
#[1] 2 3
print(x[2,3])
#[1] 6
So, does
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i, j]
}
combos$prize[i] = score(result)
}
work?
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
Hm, that seems odd. Ifnrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data andscore
to help you.
– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
add a comment |
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%2f53963494%2fusing-for-loop-to-fill-in-a-data-from-in-r-code-review%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
So your issue is with how you are creating your symbols "vector". Because a data.frame is really considered a type of "list" in R, what you are doing is assigning a 3-element list to your symbols variable. Hence, you will need to unlist this before you can make the comparisons you are seeking.
for (i in 1:nrow(combos)) {
symbols <- unlist(c(combos[i, 1], combos[i, 2], combos[i, 3]))
combos$prize[i] <- score(symbols)
}
This should solve your issue though I cannot exactly test without the combos data.frame but I assume this is your issue just looking at the code and the error message you received. Good luck!
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
add a comment |
So your issue is with how you are creating your symbols "vector". Because a data.frame is really considered a type of "list" in R, what you are doing is assigning a 3-element list to your symbols variable. Hence, you will need to unlist this before you can make the comparisons you are seeking.
for (i in 1:nrow(combos)) {
symbols <- unlist(c(combos[i, 1], combos[i, 2], combos[i, 3]))
combos$prize[i] <- score(symbols)
}
This should solve your issue though I cannot exactly test without the combos data.frame but I assume this is your issue just looking at the code and the error message you received. Good luck!
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
add a comment |
So your issue is with how you are creating your symbols "vector". Because a data.frame is really considered a type of "list" in R, what you are doing is assigning a 3-element list to your symbols variable. Hence, you will need to unlist this before you can make the comparisons you are seeking.
for (i in 1:nrow(combos)) {
symbols <- unlist(c(combos[i, 1], combos[i, 2], combos[i, 3]))
combos$prize[i] <- score(symbols)
}
This should solve your issue though I cannot exactly test without the combos data.frame but I assume this is your issue just looking at the code and the error message you received. Good luck!
So your issue is with how you are creating your symbols "vector". Because a data.frame is really considered a type of "list" in R, what you are doing is assigning a 3-element list to your symbols variable. Hence, you will need to unlist this before you can make the comparisons you are seeking.
for (i in 1:nrow(combos)) {
symbols <- unlist(c(combos[i, 1], combos[i, 2], combos[i, 3]))
combos$prize[i] <- score(symbols)
}
This should solve your issue though I cannot exactly test without the combos data.frame but I assume this is your issue just looking at the code and the error message you received. Good luck!
answered Dec 28 '18 at 22:32
Jason JohnsonJason Johnson
965
965
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
add a comment |
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
it worked!!!......so I'm curious as to why the author would provide this sort of solution without initially introducing the >>unlist function......
– dc3rd
Dec 28 '18 at 22:52
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
Yes I’m not sure why they provided an answer like that unless it’s a really old text and something in base R changed. If this answers your question please accept as an answer or if you want me to clarify anything please let me know! It’s may be because using for loops in R are pretty inefficient and they should be teaching lapply. Again best of luck!
– Jason Johnson
Dec 29 '18 at 2:06
add a comment |
Note that i:j
in combos[i:j]
returns a vector from i to j. Try to run 5:7
for example. So you're doing some 'weird' subsetting with combos[i:j]
. You probably want that to be combos[i, j]
which returns the (i, j)th entry of combos.
combos[i:j]
returns the i'th through j'th entries of combos
(which I assume is a numeric matrix). In R, matrices are stored in a column-major order, so the your intial subsetting returns the corresponding entries and might 'span the columns'. Take a look a the following to illustrate:
x <- matrix(1:6, 2, 3)
print(x)
# [,1] [,2] [,3]
#[1,] 1 3 5
#[2,] 2 4 6
print(x[2:3])
#[1] 2 3
print(x[2,3])
#[1] 6
So, does
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i, j]
}
combos$prize[i] = score(result)
}
work?
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
Hm, that seems odd. Ifnrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data andscore
to help you.
– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
add a comment |
Note that i:j
in combos[i:j]
returns a vector from i to j. Try to run 5:7
for example. So you're doing some 'weird' subsetting with combos[i:j]
. You probably want that to be combos[i, j]
which returns the (i, j)th entry of combos.
combos[i:j]
returns the i'th through j'th entries of combos
(which I assume is a numeric matrix). In R, matrices are stored in a column-major order, so the your intial subsetting returns the corresponding entries and might 'span the columns'. Take a look a the following to illustrate:
x <- matrix(1:6, 2, 3)
print(x)
# [,1] [,2] [,3]
#[1,] 1 3 5
#[2,] 2 4 6
print(x[2:3])
#[1] 2 3
print(x[2,3])
#[1] 6
So, does
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i, j]
}
combos$prize[i] = score(result)
}
work?
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
Hm, that seems odd. Ifnrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data andscore
to help you.
– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
add a comment |
Note that i:j
in combos[i:j]
returns a vector from i to j. Try to run 5:7
for example. So you're doing some 'weird' subsetting with combos[i:j]
. You probably want that to be combos[i, j]
which returns the (i, j)th entry of combos.
combos[i:j]
returns the i'th through j'th entries of combos
(which I assume is a numeric matrix). In R, matrices are stored in a column-major order, so the your intial subsetting returns the corresponding entries and might 'span the columns'. Take a look a the following to illustrate:
x <- matrix(1:6, 2, 3)
print(x)
# [,1] [,2] [,3]
#[1,] 1 3 5
#[2,] 2 4 6
print(x[2:3])
#[1] 2 3
print(x[2,3])
#[1] 6
So, does
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i, j]
}
combos$prize[i] = score(result)
}
work?
Note that i:j
in combos[i:j]
returns a vector from i to j. Try to run 5:7
for example. So you're doing some 'weird' subsetting with combos[i:j]
. You probably want that to be combos[i, j]
which returns the (i, j)th entry of combos.
combos[i:j]
returns the i'th through j'th entries of combos
(which I assume is a numeric matrix). In R, matrices are stored in a column-major order, so the your intial subsetting returns the corresponding entries and might 'span the columns'. Take a look a the following to illustrate:
x <- matrix(1:6, 2, 3)
print(x)
# [,1] [,2] [,3]
#[1,] 1 3 5
#[2,] 2 4 6
print(x[2:3])
#[1] 2 3
print(x[2,3])
#[1] 6
So, does
result = vector(length = 3)
for(i in 1:343){
for(j in 1:3){
result[j] = combos[i, j]
}
combos$prize[i] = score(result)
}
work?
edited Dec 28 '18 at 19:47
answered Dec 28 '18 at 19:41
Anders Ellern BilgrauAnders Ellern Bilgrau
6,3581729
6,3581729
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
Hm, that seems odd. Ifnrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data andscore
to help you.
– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
add a comment |
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
Hm, that seems odd. Ifnrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data andscore
to help you.
– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
It is a lot closer to working. Thanks you, I didn't see the simple mistake. Now I'm having a little issue with the function "score" I'm calling. I get the error: "Error in symbols[1] == symbols[2] : comparison of these types is not implemented"
– dc3rd
Dec 28 '18 at 19:51
Hm, that seems odd. If
nrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data and score
to help you.– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
Hm, that seems odd. If
nrow(combos)
indeed is 343 then the two are equivalent from what I can tell. Please make sure you are running it in a 'clean' R session. Does the error persist? If it does, I'm afraid I/we need to know more about your data and score
to help you.– Anders Ellern Bilgrau
Dec 28 '18 at 20:04
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
I still got the same error when I restarted R. I can paste what my >score function does. It just takes a vector of three elements, each of which is a character string, and then compares the values. I'll paste the function above.
– dc3rd
Dec 28 '18 at 20:22
add a comment |
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%2f53963494%2fusing-for-loop-to-fill-in-a-data-from-in-r-code-review%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
1
score
returns an integer value ?– YOLO
Dec 28 '18 at 19:40
@yolo yes it does
– dc3rd
Dec 28 '18 at 19:49