다음과 같은 데이터 프레임이 있습니다.
position=c("24,201", "8,915", "45,877:1","251,603")
evindence=c("RA", "RA","RA","RA")
test = data.frame(evindence,position)
evindence position
1 RA 24,201
2 RA 8,915
3 RA 45,877:1
4 RA 251,603
stringr 또는 기타 깔끔한 응용 프로그램을 사용하여 ","= ""를 대체하고 싶습니다. 그런 다음 ":"과 같은 문자열이 있으면 새 열을 만듭니다.
내 데이터 세트가 다음과 같이 보이기를 바랍니다.
evindence position insertion
1 RA 24201 NA
2 RA 8915 NA
3 RA 45877 1
4 RA 251603 NA
도움이나 지시를 주시면 감사하겠습니다
여기 깔끔한 옵션이 있습니다. 더 낫다고 말하지 않습니다. 또 다른 옵션입니다. NA에 대한 적절한 경고를 받게됩니다. 때때로 경고를 원합니다.
library(tidyverse)
position=c("24,201", "8,915", "45,877:1","251,603")
evindence=c("RA", "RA","RA","RA")
test = data.frame(evindence,position)
test %>%
mutate(position = str_replace(position, ",", "\\.")) %>%
separate(position, c("position", "insertion"), sep = ":")
#> Warning: Expected 2 pieces. Missing pieces filled with `NA` in 3 rows [1, 2, 4].
#> evindence position insertion
#> 1 RA 24.201 <NA>
#> 2 RA 8.915 <NA>
#> 3 RA 45.877 1
#> 4 RA 251.603 <NA>
reprex 패키지 (v0.3.0)에 의해 2021-01-26에 생성됨
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다