Rewrite that R code to Julia:
#"C:\Users\Michał\Desktop\player22.csv"
Data<-read.csv("C:/Users/Michał/Desktop/player22.csv")

RW_idx <- which(grepl("RW", Data$Positions))
ST_idx <- which(grepl("ST", Data$Positions))
GK_idx <- which(grepl("GK", Data$Positions))
CM_idx <- which(grepl("CM", Data$Positions))
LW_idx <- which(grepl("LW", Data$Positions))
CDM_idx <- which(grepl("CDM", Data$Positions))
LM_idx <- which(grepl("LM", Data$Positions))
CF_idx <- which(grepl("CF", Data$Positions))
CB_idx <- which(grepl("CB", Data$Positions))
CAM_idx <- which(grepl("CAM", Data$Positions))
LB_idx <- which(grepl("LB", Data$Positions))
RB_idx <- which(grepl("RB", Data$Positions))
RM_idx <- which(grepl("RM", Data$Positions))
LWB_idx <- which(grepl("LWB", Data$Positions))
RWB_idx <- which(grepl("RWB", Data$Positions))


#############



position_vectors <- list(RW_idx, ST_idx, GK_idx, CM_idx, LW_idx, 
                         CDM_idx, LM_idx, CF_idx, CB_idx, CAM_idx,
                         LB_idx, RB_idx, RM_idx, LWB_idx, RWB_idx)



position_vectors_list<-position_vectors

##############


# Mutation 2

mutate <- function(selected_players_df, position_vectors_list, probability) {
  n_rows <- nrow(selected_players_df)
  selected_players_matrix <- selected_players_df
  
  select_random_player <- function(idx_list, selected_players = NULL) {
    repeat {
      random_idx <- sample(idx_list, 1)
      if (!random_idx %in% selected_players) {
        return(random_idx)
      }
    }
  }
  
  for (i in 1:n_rows) {
    for (pos_idx in 1:length(position_vectors_list)) {
      if (runif(1) <= probability) {
        selected_players_matrix[i, pos_idx] <- select_random_player(position_vectors_list[[pos_idx]], 
                                                                    selected_players = selected_players_matrix[i, ])
      }
    }
  }
  
  selected_players_df <- data.frame(selected_players_matrix)
  return(selected_players_df)
}

n_rows<-100

pop_init<- as.data.frame(matrix(NA, n_rows, length(position_vectors)))
pop_init<- mutate(pop_init, position_vectors_list, probability=1)




#######Target

row1<-pop_init[1,]


target <- function(row1,penalty=5) {
  position_ratings <- c("RWRating", "STRating", "GKRating", "CMRating",
                        "LWRating", "CDMRating", "LMRating", "CFRating",
                        "CBRating", "CAMRating", "LBRating", "RBRating",
                        "RMRating", "LWBRating", "RWBRating")
  
  row1<-as.matrix(row1,nrow=1)
  parent_data <- Data[row1, ]
  ratings <- parent_data[position_ratings]
  ratings_log <- log(ratings)
  
  potential_minus_age <- 0.15*parent_data$Potential - 0.6*parent_data$Age
  int_reputation <- parent_data$IntReputation
  
  sumratings<-0
  rating_list<-c()
  for (i in 1:15){
    temp<-ratings_log[i,i]
    sumratings<-sumratings+temp
    rating_list<-append(rating_list, temp)
    
    
  }
  
  
  
  
  # Apply constraints
  constraint_penalty <- 0
  if (sum(parent_data$ValueEUR) > 250000000) {
    constraint_penalty <- constraint_penalty + log((sum(parent_data$ValueEUR)-250000000)^penalty)
  }
  if (sum(parent_data$WageEUR) > 250000) {
    constraint_penalty <- constraint_penalty + log((sum(parent_data$WageEUR)-250000)^penalty)
  }
  if (any(rating_list < 1.2)) {
    constraint_penalty <- constraint_penalty + 1.2^penalty
  }
  
  potential_minus_age
  
  target_value <- -(sumratings+0.3*sum(potential_minus_age) +sum(int_reputation))+constraint_penalty
  
  return(target_value)
}


#target(global_best)






parents<-pop_init
t_size=2
penalty=1

tournament_selection <- function(parents, t_size,penalty=6) {
  random_parents_idx <- sample(nrow(parents), t_size, replace = FALSE)
  random_parents <- parents[random_parents_idx, ]
  
  random_parents_fitness <- apply(random_parents, 1, function(x) target(x, penalty=penalty))
  
  
  best_parent_idx <- which.min(random_parents_fitness)
  return(random_parents[best_parent_idx, ])
}


tournament_selection (pop_init,t_size=2)


#best parent 1
#tournement_selection *50





corssover_point<-6

parent1<-row1
parent2<-pop_init[2,]



crossover <- function(parent1, parent2,corssover_point) {
  
  offspring1 <- c(parent1[1:crossover_point], parent2[(crossover_point + 1):ncol(parent1)])
  offspring2 <- c(parent2[1:crossover_point], parent1[(crossover_point + 1):ncol(parent2)])
  
  return(rbind(offspring1, offspring2))
}










###

crossover_point<-7
population_size <- 100
num_generations <- 20000
tournament_size <- 2
probability<-0.09
penalty<-1
parents<-pop_init

global_best<-pop_init[1,]
global_best_value<-target(global_best)



for (gen in 1:num_generations) {
  
  parent_pop<- as.data.frame(matrix(NA, n_rows, length(position_vectors)))
  for(c in 1:(population_size)){
    parent_pop[c,]<-tournament_selection (parents,t_size=2,penalty=penalty)
    
  }
  
  
  offspring_temp<- as.data.frame(matrix(NA, 1, length(position_vectors)))
  
  for (c in seq(1, population_size, by = 2)){
    parent1<-parent_pop[c,]
    parent2<-parent_pop[c+1,]
    
    offsprings<-crossover(parent1, parent2,corssover_point)
    o1<-unlist(offsprings[1,])
    o2<-unlist(offsprings[2,])
    
    offspring_temp<-rbind(offspring_temp,o1)
    offspring_temp<-rbind(offspring_temp,o2)
    
    
    
  }
  offspring_temp <- offspring_temp[-1, ]
  
  
  
  
  
  parents<- mutate(offspring_temp, position_vectors_list, probability=probability)
  row.names(parents) <- 1:population_size
  solutions<-apply(parents, 1, target)
  idx_sol<-which.min(solutions)[[1]]
  temp_best<-parents[idx_sol[[1]],]
  temp_target_value<-solutions[idx_sol[[1]]]
  
  if(temp_target_value<=global_best_value){
    global_best<-temp_best
    global_best_value<-temp_target_value
    
  }
  
  penalty<-penalty+0.5
  if(penalty>=4){
    penalty<-0
  }
  
}



global_best_fin<-as.matrix(global_best,nrow=1)
parent_data <- Data[global_best_fin, ]

target(global_best)

Be as careful as possible.