0

strong text Below is my objective and the code I made to represent that Row 19 is the original street text and 24 is where street2 is located https://www.opendataphilly.org/dataset/shooting-victims/resource/a6240077-cbc7-46fb-b554-39417be606ee << where the .csv is Let's deal with the streets with '&' separating their names. Create a new column named street2 and set it equal to NA. Then, iterate over the data frame using a for loop, testing if the street variable you created earlier contains an NA value. In cases where this occurs, separate the names in block according to the & delimiter into the fields street and street2 accordingly. Output the first 5 lines of the data frame to the screen. Hint: for; if; :; nrow(); is.na(); strsplit(); unlist().

NewLocation$street2 <- 'NA'

Task7 <- unlist(NewLocation)

for (col in seq (1:dim(NewLocation)[19])) {
    if (Task7[street2]=='NA'){
        for row in seq (1:dim(NewLocation[24])){
            NewLocation[row,col] <-strsplit(street,"&",(NewLocation[row,col]))
        }
    }
}
   
  • 1
    Welcome to stackoverflow! For us to be able to help you, please provide a fully "reproducible example." That means a piece of code that also contains data for us to be able to reproduce your error or problem on our own machines. You can usually do this by pasting the output of `dput(NewLocation)` into the code. – qdread Mar 11 '22 at 13:53
  • If the values are a character string 'NA' this might work. If they are coded as NA, then you need to use this logical statement instead: `is.na(Task7[street2])`. Setting it equivalent to NA won't work. There may be more the forum participants can help with. If you want great answers quickly, it's best to make your question reproducible, as @qdread said. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Mar 11 '22 at 14:16
  • https://www.opendataphilly.org/dataset/shooting-victims/resource/a6240077-cbc7-46fb-b554-39417be606ee – Freya_Luna Mar 11 '22 at 14:23
  • Above is the link to the .csv, sorry I forgot to share that – Freya_Luna Mar 11 '22 at 14:24

0 Answers0