-1
如果沒有簡單的解決方案,這會使面部手掌像冠軍一樣,我會感到震驚。使用命名字符向量替換數據框中的行
我正在構建一個DF的顏色來製作一個網絡圖文件。當用戶與GUI進行交互時,某些行會更改爲與某些邊緣和節點顏色相對應。
這裏有一個小例子:
node_col_1 <- c(red=0, green=153, blue=255, alpha=1)
node_col_2 <- c(red=163, green=160, blue=25, alpha=1)
test_colors <-
t(
sapply(
seq_len(5),
FUN= function(x) node_col_1
)
)
所以test_colors是:
red green blue alpha
[1,] 0 153 255 1
[2,] 0 153 255 1
[3,] 0 153 255 1
[4,] 0 153 255 1
[5,] 0 153 255 1
然後,試圖更換行2和3:
> test_colors[c(2,3), ]<- node_col_2
red green blue alpha
[1,] 0 153 255 1
[2,] 163 25 163 25
[3,] 160 1 160 1
[4,] 0 153 255 1
[5,] 0 153 255 1
這取而代之逐列(在平坦的DF),而不是明智的。有沒有簡單的方法來做這個替換?
你在那裏沒有data.frame。這是一個矩陣。 – Roland
啊。這將是我第一次嘗試的主要問題。 \ * facepalm \ * – bigfoot56