Re: [R] creating txt file from data.frame

From: Vladimir Eremeev <wl2776_at_gmail.com>
Date: Mon, 28 May 2007 03:09:17 -0700 (PDT)

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.

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 28 May 2007 - 10:13:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 May 2007 - 12:31:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.