Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a result of function in the global environment in R

I have these datasets: A <- 4, B <- 3, C <- 2.

So I put them in a list D<-list(A,B,C) and want to apply this function:

s<-function(x) {
    t<-8
    x<-as.data.frame(x*t)
}

lapply(D,s)

when I apply the lapply function it just print them.

How can I make it saving the result in the global environment instead of printing them?

So the result should be A with value of 32 B with value of 24 C with value of 16.

like image 475
Kingindanord Avatar asked Dec 23 '22 17:12

Kingindanord


1 Answers

Instead of lapply(D,s), use:

D <- lapply(D, s)
names(D) <- c("A", "B", "C")
list2env(D, envir = .GlobalEnv)
like image 177
Leandro Mineti Avatar answered Jan 31 '23 05:01

Leandro Mineti