R:将DIMNAME转换为矩阵中的列
我试图用它来分析我的数据。 按照“tsne”的“自述”中使用的示例数据(“iris”), 我试图以一种可以用作tsne()函数输入的方式构造自己的数据R:将DIMNAME转换为矩阵中的列,r,matrix,dataframe,R,Matrix,Dataframe,我试图用它来分析我的数据。 按照“tsne”的“自述”中使用的示例数据(“iris”), 我试图以一种可以用作tsne()函数输入的方式构造自己的数据 >sampledata Gene 1 Gene 2 Gene 3 Gene 4 GeneX Cell1 Value Value Value Value Value Cell2 Value Value Value Value Value Cell3 Value Value
>sampledata
Gene 1 Gene 2 Gene 3 Gene 4 GeneX
Cell1 Value Value Value Value Value
Cell2 Value Value Value Value Value
Cell3 Value Value Value Value Value
Cell4 Value Value Value Value Value
Cell5 Value Value Value Value Value
与“iris”相比,我想我需要添加一个额外的列,使用dimnames“Cell1”“Cell2”“Cell3”
对于dataframe,我想我可以简单地执行以下操作:
sampledata$sampleids<-rownames(sampledata)
sampledata$sampleids我们可以cbind
但是将数值
矩阵与字符
元素混合会产生字符
矩阵
sampledata <- cbind(sampledata, sampleids=rownames(sampledata))
sampledata我不知道tsne,但矩阵包含相同类型的值。如果其值是数字,则不能添加字符串。@user31264,是的,矩阵包含相同类型的值。谢谢你提醒我这一点(我这周才知道,所以这个事实还没有在我的脑海中扎根…)。在重新检查“自述”部分后,实际上tsne\u
sampledata <- cbind(sample(data, sampleids = seq_len(nrow(sampledata)))