How To Create Vector of Vector In R

0 votes
have lines like this in your supplied data:

0.695282 -0.438185 -0.766791

0.524807 0.759100 0.034400

In R, how can I make a data structure that looks like this:

[[1]]

-0.438185 -0.766791 0.695282 -0.438185 -0.766791 -0.766791 -0.766791 -0.76679

[[2]]

[1] 0.759100 0.034400 0.524807 0.759100 0.034400 0.524807 0.759100 0.034400 0.52
Jun 10, 2022 in Data Science by Avinash
• 1,260 points
489 views

1 answer to this question.

0 votes

Create a list:

List() on x returns x[[1]] <- c(-0.438185, -0.766791, 0.695282) > x[[2]] <- c (-0.759100, 0.034400, 0.524807)

> x [[1]] \s[1] -0.438185 -0.766791 0.695282

[[2]]
[1] -0.759100 0.034400 0.524807
Imagine it as an integer-indexed map, dictionary, or associative array.

And if you want to create a list of vectors from a string similar to the one above:

> s = "-0.438185 -0.766791 0.695282n0.759100 0.034400 0.524807" > x = "lapply(strsplit(s, "n")[[1]], function(x)" > x = "x [[1]]"
[1] -0.438185 -0.766791 0.695282

[[2]]
[1] 0.759100 0.034400 0.524807
I'm splitting lines with strsplit by newlines and then using strsplit once more to split each line. As.numeric is used to convert strings to numbers, and [[1]]s are used since strsplit generates a list rather than the single-valued result we are after.

Discover the world of data with our Data Science Course and embark on a transformative journey towards analytical excellence.

answered Jun 24, 2022 by Sohail
• 3,040 points

Related Questions In Data Science

0 votes
0 answers

How to manually find the minors of a matrix in R programming?

I have to write a function that ...READ MORE

Jul 5, 2022 in Data Science by avinash
• 1,840 points
453 views
0 votes
0 answers

how to make 2 separate substrings from strsplit in R

When it comes to accessing the elements ...READ MORE

Jun 13, 2022 in Data Science by Avinash
• 1,260 points
315 views
0 votes
1 answer

How to implement Knn-algorithm without using k-nn function in r?

I created an example that demonstrates the ...READ MORE

answered Jun 24, 2022 in Data Science by Sohail
• 3,040 points
469 views
0 votes
1 answer

grepl in R to find matches to any of a list of character strings

Inside of a grepl regular expression, you ...READ MORE

answered Jun 24, 2022 in Data Science by Sohail
• 3,040 points
3,218 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,042 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,203 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,904 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,140 views
0 votes
1 answer

How to make loop for one-at-a time logistic regression in R?

You're probably looking for something similar to ...READ MORE

answered Jun 20, 2022 in Data Science by Sohail
• 3,040 points
1,059 views
0 votes
1 answer

How to overlay density plots in R?

The second one has 104 usage lines: plot(density(MyData$Column1)) ...READ MORE

answered Jun 24, 2022 in Data Science by Sohail
• 3,040 points
1,023 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP