当前位置:网站首页>Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]

Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]

2022-07-06 20:51:00 Rich in starch

problem :

This question already has answers here : This question has been answered here
Closed 4 years ago .4 Years ago close .

I have a data table with a bunch of columns, eg: I have a data table with a bunch of columns , for example :

dt<-data.table(matrix(runif(10*10),10,10))

I want to perform some operation on the data table, such as producing a correlation matrix ( cor(dt) ). I want to perform some operations on the data table , For example, generate correlation matrix ( cor(dt) ).In order to do this, I want to remove a few columns that contain non-numeric values or values outside a certain range. So , I want to delete some columns that contain non numeric values or values outside a specific range .

Let's say I want to find the correlation matrix excluding V1, V2, V3 and V5. Suppose I want to find something that doesn't include V1、V2、V3 and V5 The correlation matrix of .

Here is my current approach: This is my current method :

cols<-!(colnames(dt)=="V1" | colnames(dt)=="V2" | colnames(dt)=="V3" | colnames(dt)=="V5")new_dt<-subset(dt,,cols)cor(new_dt)

I find this pretty cumbersome, considering data.table syntax is usually so elegant. I think it's troublesome , because data.table Grammar is usually very elegant .Is there a better method of doing this? There is no better way to do this ?


Solution :

Reference resources : https://stackoom.com/en/question/1tshR
原网站

版权声明
本文为[Rich in starch]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131142356402.html