in Education by
I'd like to rename objects in environment r. For example, y1 <- vector('list', 3) x1 <- matrix(0, 3, 3) x2 <- matrix(1, 3, 3) x3 <- matrix(2, 3, 3) y1[[1]] <- x1 y1[[2]] <- x2 y1[[3]] <- x3 y2 <- vector('list', 3) y2[[1]] <- x1 y2[[2]] <- x2 y2[[3]] <- x3 y <- new.env() y$y1 <- y1 y$y2 <- y2 names(y) names(y) <- c('a', 'b') I expected that the name of lists inside y was a and b, that is, names(y) equals c('a', 'b'), Obs.: I can't rename manually the variables y1 and y2, I need to change them inside the environment. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
R doesn't really have a built in operation to rename variables in any environment. YOu could write a simple helper function to do that. env_rename <- function(e, new_names, old_names = names(e)) { stopifnot(length(new_names)==length(old_names)) orig_val <- mget(old_names, envir=e) rm(list=old_names, envir=e) for(i in seq_along(old_names)) { assign(new_names[i], orig_val[[i]], envir=e) } } and call that with env_rename(y, c("a","b"))

Related questions

0 votes
    What is the command used to store R objects in a file? (a) save (x, file= x.Rdata ) (b) save ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    In R language, a vector is defined that it can only contain objects of the ________ (a) Same class (b) ... Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    R objects can have attributes, which are like ________ for the object. (a) metadata (b) features (c) ... Out of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Factors are the r-objects which are created using a _________ (a) Vector (b) Matrix (c) Lists (d) Array ... and Out of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which of the following can be used to display the names of (most of) the objects which are currently stored ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    The current user defined objects like lists, vectors, etc. is referred to as __________ in the R language. ( ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Individual R objects can be saved to a file using the _____ function. (a) save (b) put (c) save_image ... Operations of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    We can dump() R objects to a file by passing _____ (a) character vector of their names (b) object name ... Operations of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Advanced users can write ___ code to manipulate R objects directly. (a) C, C++ (b) C++, Java (c) ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    The four most frequently used types of data objects in R are vectors, matrices, data frames and ________ (a) ... Out of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Advanced programmers can write ______ code to manipulate R objects. (a) Python (b) Java (c) C (d) Java ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    R has how many atomic classes of objects? (a) 1 (b) 2 (c) 3 (d) 5 I got this question in an ... Data In and Out of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    If we want to save individual R objects to a file, we use the _______ function. (a) save() (b) save ... and Operations of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    _________ package provides basic functionalities in R environment like arithmetic calculations, input/output. (a) R ... R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Write the syntax to set the path of the current working directory in R environment? (a) Setwd( dipath ) ... Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
...