Iterating over characters of string R

前端 未结 4 861
一整个雨季
一整个雨季 2021-02-19 10:24

Could somebody explain me why this does not print all the numbers separately in R.

numberstring <- \"0123456789\"

for (number in numberstring) {
  print(num         


        
4条回答
  •  梦如初夏
    2021-02-19 10:39

    Your question is not 100% clear as to the desired outcome (print each character individually from a string, or store each number in a way that the given print loop will result in each number being produced on its own line). To store numberstring such that it prints using the loop you included:

    numberstring<-c(0,1,2,3,4,5,6,7,8,9)
    for(number in numberstring){print(number);}
    
    [1] 0
    [1] 1
    [1] 2
    [1] 3
    [1] 4
    [1] 5
    [1] 6
    [1] 7
    [1] 8
    [1] 9
    > 
    

提交回复
热议问题