Ask Your Question
2

How can I turn a string of characters into a list using R?

asked 2022-09-17 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-25 17:00:00 +0000

huitzilopochtli gravatar image

You can turn a string of characters into a list using the strsplit() function in R.

For example, let's say you have a string of characters "hello world":

mystring <- "hello world"
mylist <- strsplit(mystring, " ")

In this example, we use the strsplit() function to split the string at each space, creating a list with two elements:

[[1]]
[1] "hello"

[[2]]
[1] "world"

The double brackets show that the list has two elements, and each element is a character vector with one value.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-17 11:00:00 +0000

Seen: 11 times

Last updated: Aug 25 '21