Use a list:
> x <- list() > x[[1]] <- c(-0.438185, -0.766791, 0.695282) > x[[2]] <- c(-0.759100, 0.034400, 0.524807) > x [[1]] [1] -0.438185 -0.766791 0.695282 [[2]] [1] -0.759100 0.034400 0.524807
Think of it as a map/dictionary/associative array that is being indexed by an integer.
And if you want to take a string like the one above and turn it into a list of vectors:
> s <- "-0.438185 -0.766791 0.695282\n0.759100 0.034400 0.524807" > x <- lapply(strsplit(s, "\n")[[1]], function(x) {as.numeric(strsplit(x, '\\s+')[[1]])}) > x [[1]] [1] -0.438185 -0.766791 0.695282 [[2]] [1] 0.759100 0.034400 0.524807
I’m using strsplit to split by newlines, then applying strsplit again to each line. The as.numeric is there to cast from strings to numbers and the [[1]]’s are there because strsplit outputs a list, which we don’t really want.
Related Posts:
- How to remove outliers from a dataset
- dplyr: “Error in n(): function should not be called directly”
- Error in eval(expr, envir, enclos) : object not found
- How do I convert a factor into date format?
- Write lines of text to a file in R
- scale_fill_discrete and scale_fill_manual – legend options confusion
- ‘Incomplete final line’ warning when trying to read a .csv file into R
- Conditional mean statement
- Warning in GLM analysis
- What does ‘length of ‘dimnames’ [1] not equal to array extent’ mean?
- How do I flip rows and columns in R
- How to catch integer(0)?
- “no function to return from, jumping to top level”
- r random forest error – type of predictors in new data do not match
- env=baseenv() in R
- Removing punctuations from text using R
- How to find out which package version is loaded in R?
- How to solve it. error:Error in data[[rowvar]] : attempt to select less than one element
- Gradient of n colors ranging from color 1 and color 2
- How to prevent scientific notation in R?
- What is the difference between require() and library()?
- How to declare a vector of zeros in R
- R Sweave: NO TeX installation detected
- ERROR: [on_request_read] connection reset by peer in R shiny
- Error in as.vector(x, mode) : cannot coerce type ‘closure’ to vector of type ‘any’
- Suppress output of a function
- Error in G * t(hat) : non-conformable arrays
- Error: isTRUE(gpclibPermitStatus()) is not TRUE
- How to counter the ‘non-numeric matrix extent’ error in R?
- What does is.na() applied to non-(list or vector) of type ‘NULL’ mean?
- error r: invalid subscript type “closure” in a simple regression
- Merge two rows in data.frame
- r function unzip error 1 in extracting from zip file
- Get the list of installed packages by user in R
- Colour points in a plot differently depending on a vector of values
- How to access the last value in a vector?
- increase legend font size ggplot2
- Mask output of `The following objects are masked from….:` after calling attach() function
- Use of ~ (tilde) in R programming Language
- Construct a manual legend for a complicated plot
- Code to clear all plots in RStudio
- Error: x must be atomic for ‘sort.list’
- Installing R on Android
- Transposing in dplyr
- Does the c command create a row vector or a column vector by default in R
- Convert data.frame column to a vector?
- Error in summary.connection(connection) : invalid connection
- Converting from a character to a numeric data frame
- How to create lag variables
- When trying to replace values, “missing values are not allowed in subscripted assignments of data frames”
- Non-numeric Argument to Binary Operator Error in R
- Error in file(file, “rt”) : invalid ‘description’ argument in complete.cases program
- Logistic Regression on factor: Error in eval(family$initialize) : y values must be 0 <= y <= 1
- R – longer object length is not a multiple of shorter object length
- Plot multiple lines in one graph
- How to read in .HTM into R as a data frame?
- Warning message: line appears to contain embedded nulls [duplicate]
- Find duplicate values in R
- Transpose a data frame
- How to drop columns by name in a data frame
- Multiple If Statements in R
- ggplot geom_text font size control
- ggplot2, change title size
- Initial value in ‘vmmin’ is not finite even when changing the starting value
- Insert picture/table in R Markdown
- Test if a vector contains a given element
- Insert a blank column in dataframe
- “length of ‘dimnames’ [2] not equal to array extent” on one of two very similar sets
- How to install RHadoop packages (Rmr, Rhdfs, Rhbase)?
- Warning message: In `…` : invalid factor level, NA generated
- “non-numeric argument to binary operator” error in R
- Replace all particular values in a data frame
- promise already under evaluation: recursive default argument reference or earlier problems?
- Position-dodge warning with ggplot boxplot?
- Plot two graphs in same plot in R
- KNN in R: ‘train and class have different lengths’?
- Error in rep(1, n.ahead) : invalid ‘times’ argument in R
- Producing subscripts in R markdown
- ggplot geom_text font size control
- How do you use “<<-" (scoping assignment) in R?
- Remove quotes from a character vector in R
- Is it possible to have a multi-line comments in R?
- R – error “variable lengths differ”
- how to increase the limit for max.print in R
- In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)
- Replace NA with 0 in a data frame column [duplicate]
- Error while creating heatmaps – NA/NaN/Inf in foreign function call (arg 11)
- Error in xj[i] : invalid subscript type ‘list’
- How do you specifically order ggplot2 x axis instead of alphabetical order?
- How to solve ‘protection stack overflow’ issue in R Studio
- Error in 2:n : NA/NaN argument
- Does R have a wildcard expression (such as an asterisk (*))?
- Simple for loop in R producing “replacement has length zero” in R
- Batch convert columns to numeric type
- What does Continuous x aesthetic — did you forget aes(group=…) mean?
- How to unload a package without restarting R
- Plotting legend outside plot in R
- Reset par to the default values at startup
- How to increase the font size of ggtitle in ggplot2
- What is the meaning of the dollar sign “$” in R function()?