apply(dfr,1,FUN=function(x){
cat(c(x[1],
ifelse(x[2]==x[3],x[2],paste(x[2],x[3],sep="-")),"\n"),
file="filename.txt")
})
This code assumes the data frame with at least 3 columns, errors will occur
if there will be less than 3 columns.
Taka Matzmoto wrote:>
> R-users
> I need to create a txt file as input for another program using data.frame
> values
>
> Variable_name Start End
> [1,] "aaaaaaaaaaaaa" "1" "1"
> [2,] "bbbbbbbbbbb" "2" "2"
> [3,] "ccccccccccccc" "3" "6"
> [4,] "ddddddddddd" "7" "10"
> [5,] "eeeeeeeeeee" "11" "16"
>
>
> the text file should look like below,
> if the start and the end is the same, only put the start one in the txt
> file.
>
> aaaaaaaaaaaaa 1
> bbbbbbbbbbb 2
> ccccccccccccc 3-6
> ddddddddddd 7-10
> eeeeeeeeeee 11-16
>
--
View this message in context:
http://www.nabble.com/creating-txt-file-from-data.frame-tf3825900.html#a10833782
Sent from the R help mailing list archive at Nabble.com.