I'm having trouble finding the equivalent functions for these python codes in R:
def function1(): for char in "some words and stuff": if (char == "e"): break print ("Here is:", char)
def function2(): for char in "Some words and stuff": if (char == "d"): pass print ("Here is:", char)
def function3(): for numbers in range(21): if numbers <= 10: print("included: " + str(numbers)) continue elif numbers > 10: break print ("go", numbers)
So far I have:
function1 <- function(){ for(i in "Some words and stuff") if(i == "e"){ break } print (i) }
function2 <- function(){ for(i in "Some words and stuff") if (i == "D"){ next } print (i) }
function3 <- function(){ for x2 in (1,21) if(x2 <= 10){ next} else if(x2 > 10){} break } print (x2) }
The first two print out the whole "some words and stuff" and the last has a } error. I just want the last one to list 1-10. It's not important to include the "Here is" or "included" or "go".
https://stackoverflow.com/questions/66094604/python-codes-not-working-when-translated-to-r February 08, 2021 at 08:43AM
没有评论:
发表评论