Quantcast
Viewing all articles
Browse latest Browse all 4448

How to impute or do r bind lists in for loop?

@premsheth wrote:

Hi Friends,

I am encountered with one problem I guess it is easy for an experienced person but I am unable to solve it.
When I run the code outside for loop, I get desired output.

s <- stringdist::stringdistmatrix(stri_extract_first_words(talent[,2][1]),company[,1], method = "jaccard")
d <- company[apply(s,1, which.min),]

s <- stringdist::stringdistmatrix(stri_extract_first_words(talent[,2][2]),company[,1], method = "jaccard")
e <- company[apply(s,1, which.min),]

s <- stringdist::stringdistmatrix(stri_extract_first_words(talent[,2][3]),company[,1], method = "jaccard")
f<- company[apply(s,1, which.min),]

s <- stringdist::stringdistmatrix(stri_extract_first_words(talent[,2][4]),company[,1], method = "jaccard")
g <- company[apply(s,1, which.min),]

s <- stringdist::stringdistmatrix(stri_extract_first_words(talent[,2][8]),company[,1], method = "jaccard")
h <- company[apply(s,1, which.min),]

full <- rbind(d,e,f,g,h)
full

Output:
title location_name_list
42 Job one Louisville, KY, United States
14 job San Francisco, CA, United States
421 Job one Louisville, KY, United States
141 job San Francisco, CA, United States
422 Job one Louisville, KY, United States

But Now I use for loop for it I am not getting how to get this output
I tried rbind lists, impute data row wise in matrix etc.
But Didn’t get desire output as above

For loop code:

d <- NULL
for (i in 1:length(talent[,1])) {
  s <- stringdist::stringdistmatrix(stri_extract_first_words(talent[,2][i]),company[,1], method = "jaccard")
  d[i] <- company[apply(s,1, which.min),]
  full <- rbind(d[i-1], d[i])
} 

can anyone please help me how can I impute data in data frame or in matrix?

Thanks in Advance

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles