이 질문은 previous question과 거의 같지만 질문에 대한 대답이 여기에서 작동하지 않을만큼 다릅니다. 마지막 질문에서 @chase처럼 데이터 프레임의 각 분할에 대해 여러 파일을 다음 형식 (사용자 정의 fasta)으로 작성하려고합니다.d_ply를 사용하여 여러 사용자 정의 파일 작성
#same df as last question
df <- data.frame(
var1 = sample(1:10, 6, replace = TRUE)
, var2 = sample(LETTERS[1:2], 6, replace = TRUE)
, theday = c(1,1,2,2,3,3)
)
#how I want the data to look
write(paste(">", df$var1,"_", df$var2, "\n", df$theday, sep=""), file="test.txt")
#whole df output looks like this:
#test.txt
>1_A
1
>8_A
1
>4_A
2
>9_A
2
>2_A
3
>1_A
3
그러나, 대신 전체 dataframe의 출력을 얻는 나는 데이터의 각 부분 집합에 대한 개별 파일을 생성합니다. 다음과 같이 d_ply
사용 :
d_ply(df, .(theday), function(x) write(paste(">", df$var1,"_", df$var2, "\n", df$theday, sep=""), file=paste(x$theday,".fasta",sep="")))
나는 다음과 같은 출력 오류 얻을 :이 문제를 해결하는 방법에 대한
Error in file(file, ifelse(append, "a", "w")) :
invalid 'description' argument
In addition: Warning messages:
1: In if (file == "") file <- stdout() else if (substring(file, 1L, :
the condition has length > 1 and only the first element will be used
2: In if (substring(file, 1L, 1L) == "|") { :
the condition has length > 1 and only the first element will be used
어떤 제안?
덕분에, zachcp
빠르고 멋지다. – zach
@zach - 고마워. 나는 익명 함수 (즉,'function (x) {browser(); write .....}'의 본문에'browser()'호출을 즉시 두었습니다. 그렇게함으로써, 당신은 여가 시간에 환경과 계산의 각 부분을 둘러 볼 수 있고, 무엇이 잘못되었는지를 빨리 볼 수 있습니다. –
좋은 팁! 감사 – zach