-2

Have code below where I am trying to pick out the unique zone names then iterate through , however when I run it it just prints out 1 line.

This is my code:

 ZonelistName<-unique(temp[c("zone")])
  
  #this is where the LSD for the zone will be
  
  for (p in c(ZonelistName)) {
    print(p)
  }

Which prints out:

# > [1] 3 2 5 1



   dput(head(ZonelistName))
structure(list(zone = c(3, 2, 5, 1)), row.names = c(NA, -4L), class = c("tbl_df", 
"tbl", "data.frame"))

sorry i cant reproduce it as i dont know what that object is

R.Merritt
  • 477
  • 5
  • 17
  • Did you look at the contents of ZonelistName? Say with `head(ZonelistName)` ? – G5W Aug 20 '20 at 21:00
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What exactly is `temp`? – MrFlick Aug 20 '20 at 21:01
  • Give us output of `dput(head(ZonelistName))`. – M-- Aug 20 '20 at 21:47
  • I think what you need is `ZonelistName <- unique(temp$zone)` – Ronak Shah Aug 21 '20 at 01:11

1 Answers1

0

I guess you might need unlist rather than c

for (p in unlist(ZonelistName)) {
  print(p)
}

or

for (p in ZonelistName$zone) {
  print(p)
}

which gives

[1] 3
[1] 2
[1] 5
[1] 1
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81