R extract data frame from list without prefixes in column names -


i place data frame inside list. when try extract - column names prefixed list key data frame, there way extract data frame passed initially?

cols<-c("column1", "column2", "column3") df1<-data.frame(matrix(ncol = 3, nrow = 1)) colnames(df1)<-cols df1  result<-list() result['df1']<-list(df1)  newdf1<-as.data.frame(result['df1']) newdf1 

get result (column names prefixed df1):

> cols<-c("column1", "column2", "column3") > df1<-data.frame(matrix(ncol = 3, nrow = 1)) > colnames(df1)<-cols > df1   column1 column2 column3 1      na      na      na >  > result<-list() > result['df1']<-list(df1) >  > newdf1<-as.data.frame(result['df1']) > newdf1   df1.column1 df1.column2 df1.column3 1          na          na          na 

of course, can remove prefixes manually, there proper way this. thanks!

extract using [[ rather [:

> newdf1 <- as.data.frame(result[['df1']]) > newdf1   column1 column2 column3 1      na      na      na 

the difference [ extracts list containing requested component(s). [[ extracts requested component directly (i.e. retrieves contents of component of list, not list containing component).

but df1 is data frame, why not do:

newdf1 <- result[['df1']] 

? don't need as.data.frame() part.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -