function with loop function

a function that accepts a vector, that loops over each element of the vector and returns a vector of characters

function_1 <- function(a){
for (i in seq_along(length(a))) {
my.result <- "a"
return(my.result)

}
}
function_1()

function that solves the problem in one step using subsetting

how can i solve these problem?

The way you describe your function doesn't match its current functionality, which always is to return a fixed 'a' response.

It would be easier to help you if we were clear in what you want to achieve.
To turn any vector into a character vector. the command as.character() is likely the best one liner approach, it could be that simple ?

You are asking me about number 3 something, but this question you ask me about '3' is the only time there are any 3's on this page, so I'm confused...

#3 function that solves the problem in one step using subsetting
b <- c(2, 5, 7, 8)
subsetting_function <- function (a){
my.result <- a [ ]
return(my.result)

}
subsetting_function(b[4])

sorry . i am asking this one

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.