조건에 따라 행 이름에 문자를 추가하려는 큰 데이터 프레임이 있습니다. 내가 문자를 추가 붙여 넣기를 사용할 수 있습니다 알고조건에 따라 행 이름에 문자를 추가하십시오.
char number
birch flower 3
pine c cone 3
maple flower 5
redwood c cone 6
:
trees <- data.frame(char = c('flower', 'cone', 'flower', 'cone'), number = c(3, 3, 5, 6))
rownames(trees) <- c('birch', 'pine', 'maple', 'redwood')
이 내가 옆에 소나무와 레드 우드에 'C', 갈거야 무엇을 : 나는 다음과 같은 예를
나는 코드의 다음 줄을하려고 할 때# this gives the output I am looking for
paste(rownames(trees[trees$char == 'cone',]), 'c')
[1] "pine c" "redwood c"
그러나, 변경 내 데이터 프레임에 표시되지 않습니다 :
rownames(trees[trees$char == 'cone',]) <- paste(rownames(trees[trees$char == 'cone',]), 'c')
두 번째 옵션으로갔습니다. 고맙습니다. – Danny