[R] comparing two strings from data
Yasin Gocgun
yasing053 at gmail.com
Thu Oct 12 22:25:35 CEST 2017
Hi,
I have two columns that contain numbers along with letters (as shown below)
and have different lengths. Each entry in the first column is likely to be
found in the second column at most once.
For each entry of the first column, if that entry is found in the second
column, I would like to get the corresponding index. For instance, if the
first entry of the first column is 5th entry in the second column, I would
like to keep this index 5.
AST2017000005534 TUR2017000001428
CTS2017000079930 CTS2017000071989
CTS2017000079931 CTS2017000072015
In a loop, when I use the following code to get those indices,
data_2 = read.csv("excel_data.csv")
column_1 = data_2$data1
column_2 = data_2$data2
match_list <- array(0,dim=c(310,1)); # 310 is the length of the first
column
for (indx in 1: 310){
for(indx2 in 1:713){ # 713 is the length of the second column
if(column_1[indx] == column_2[indx2] ){
match_list[indx,1] = indx2;
break;
}
}
}
R provides the following error:
Error in Ops.factor(column_1[indx], column_2[indx2]) :
level sets of factors are different
So can someone explain me how I can resolve this issue?
Thnak you,
Yasin
[[alternative HTML version deleted]]
More information about the R-help
mailing list