Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否将索引表转换为字符矩阵(或df)?在R_R_Matrix_Indexing - Fatal编程技术网

是否将索引表转换为字符矩阵(或df)?在R

是否将索引表转换为字符矩阵(或df)?在R,r,matrix,indexing,R,Matrix,Indexing,我总是犯奇怪的错误。这个逻辑在我看来是合理的。你能看看下面的代码并提供一些见解吗?谢谢 rw <- c(1,1,1,2,2,2,3,3,3) cl <- c(1,2,3,1,2,3,1,2,3) ch <- c("A","bv","c","dog","cat","bird","red", "yel","fuscia") df <- data.frame(rw, cl, ch) df l

我总是犯奇怪的错误。这个逻辑在我看来是合理的。你能看看下面的代码并提供一些见解吗?谢谢

    rw      <- c(1,1,1,2,2,2,3,3,3)
    cl      <- c(1,2,3,1,2,3,1,2,3)
    ch      <- c("A","bv","c","dog","cat","bird","red", "yel","fuscia")
    df      <- data.frame(rw, cl, ch)
    df
    layout  <- matrix(NA, nrow=3, ncol=3)
    layout[df[,1:2]] <- df[,3]

rw按照您原来的计划,矩阵索引需要一个
矩阵
,而不是
数据框架

layout[as.matrix(df[,1:2])] <- as.character(df[,3])

layout[as.matrix(df[,1:2])]成功!非常感谢。
layout[as.matrix(df[,1:2])] <- as.character(df[,3])