Answer the question
In order to leave comments, you need to log in
R how to make a subset on several fields in a loop?
I have data
field1 field2 field3 field4 field5 field6 field7 field8
text text1 segment_1 31-Jan-13 2.7 0.21 1.44 1.29
text text1 segment_1 01-May-13 0.7 2.90 0.76 0.38
text text1 segment_1 31-Jul-13 -2.3 -0.95 -1.73 -1.95
for (j in 1:length(unique(InputData[,3]))) {
InputDataSubset <- InputData[InputData[,3] == unique(InputData[,3])[j],]
print(unique(InputData[,3])[j])
print(InputDataSubset)
}
for (j in 1:length(unique(InputData[,1:3]))) {
InputDataSubset <- InputData[InputData[,1:3] == unique(InputData[,1:3])[j,],]
print(unique(InputData[,3])[j])
print(InputDataSubset)
}
Error in Ops.data.frame(InputData[, 1:3], unique(InputData[, 1:3])[j, :
'==' only defined for equally-sized data frames
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question