Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing name of dataframe into a loop in r

Here is just small example of my problem:

myfun <- function (dataframe) {
namef <- paste (dataframe, ".raw", sep = "")
return(namef)
}
xy <- data.frame (A = 1:10, B = 11:20)

myfun(xy)
[1] "1:10.raw"  "11:20.raw"

What I want to return is name of file "xy.raw" in this case.

names(dataframe) will not work as it will give the names of data frame columns.

like image 838
jon Avatar asked Jan 27 '26 10:01

jon


1 Answers

Try :

paste(substitute(dataframe),".raw,sep="")
like image 176
Matt Dowle Avatar answered Jan 29 '26 00:01

Matt Dowle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!