R loops with indices
up vote
0
down vote
favorite
I am refreshing my R loops skills. How can I write a loop for the below codes. The column indices are 10:14.
length(data[which(data$subject == "notcoded"),"subject"])/length(data[,"subject"])
here:
for (i in 10:14){
length(data[which(data[i] == "notcoded")[[i]]])/length(data[i])
}
I kept getting errors about undefined column. I have tried multiple ways to use and []
r
add a comment |
up vote
0
down vote
favorite
I am refreshing my R loops skills. How can I write a loop for the below codes. The column indices are 10:14.
length(data[which(data$subject == "notcoded"),"subject"])/length(data[,"subject"])
here:
for (i in 10:14){
length(data[which(data[i] == "notcoded")[[i]]])/length(data[i])
}
I kept getting errors about undefined column. I have tried multiple ways to use and []
r
You are subsetting your data but not specifying a column. Usedata[,i]
– Michael Harper
Nov 10 at 16:07
3
Possible duplicate of Undefined columns selected when subsetting data frame
– Michael Harper
Nov 10 at 16:09
Thank you Michael.
– mchsu
Nov 11 at 16:00
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am refreshing my R loops skills. How can I write a loop for the below codes. The column indices are 10:14.
length(data[which(data$subject == "notcoded"),"subject"])/length(data[,"subject"])
here:
for (i in 10:14){
length(data[which(data[i] == "notcoded")[[i]]])/length(data[i])
}
I kept getting errors about undefined column. I have tried multiple ways to use and []
r
I am refreshing my R loops skills. How can I write a loop for the below codes. The column indices are 10:14.
length(data[which(data$subject == "notcoded"),"subject"])/length(data[,"subject"])
here:
for (i in 10:14){
length(data[which(data[i] == "notcoded")[[i]]])/length(data[i])
}
I kept getting errors about undefined column. I have tried multiple ways to use and []
r
r
asked Nov 10 at 16:03
mchsu
163
163
You are subsetting your data but not specifying a column. Usedata[,i]
– Michael Harper
Nov 10 at 16:07
3
Possible duplicate of Undefined columns selected when subsetting data frame
– Michael Harper
Nov 10 at 16:09
Thank you Michael.
– mchsu
Nov 11 at 16:00
add a comment |
You are subsetting your data but not specifying a column. Usedata[,i]
– Michael Harper
Nov 10 at 16:07
3
Possible duplicate of Undefined columns selected when subsetting data frame
– Michael Harper
Nov 10 at 16:09
Thank you Michael.
– mchsu
Nov 11 at 16:00
You are subsetting your data but not specifying a column. Use
data[,i]
– Michael Harper
Nov 10 at 16:07
You are subsetting your data but not specifying a column. Use
data[,i]
– Michael Harper
Nov 10 at 16:07
3
3
Possible duplicate of Undefined columns selected when subsetting data frame
– Michael Harper
Nov 10 at 16:09
Possible duplicate of Undefined columns selected when subsetting data frame
– Michael Harper
Nov 10 at 16:09
Thank you Michael.
– mchsu
Nov 11 at 16:00
Thank you Michael.
– mchsu
Nov 11 at 16:00
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240771%2fr-loops-with-indices%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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
You are subsetting your data but not specifying a column. Use
data[,i]
– Michael Harper
Nov 10 at 16:07
3
Possible duplicate of Undefined columns selected when subsetting data frame
– Michael Harper
Nov 10 at 16:09
Thank you Michael.
– mchsu
Nov 11 at 16:00