Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm learning R right now but I can't find a solution for my problem. I'd like to create 100 files with a text line inside, let's say "Hello world!". Does anyone know how to do it?
Use a for loop and write_lines for example:
for(i in 1:100) {
write_lines("Hello World", path = sprintf("file%s.txt", i))#
}
or use mapply
mapply(write_lines, path = sprintf("file%s.txt", 1:100), x = "Hello World")
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to make a function within a function?
My goal is to insert the function inside the function.
Here is an example of function inside a function
f <- function(n) {
g <- function(x) {
x**n
}
}
such that
> f(3)(4)
[1] 64
But I have no idea what you are exactly after...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there a function such as kable to output character vectors in a way that doesn't look as ugly as the default console type?
See eg p from the pander package or the generic pander method:
> pander::pander(sample(letters, 5))
_p_, _r_, _v_, _f_ and _t_
If you want to override the default formatting, see panderOptions or specify directly in the p function.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to write this (SAS) comand in R. x is a variable with this specific format: j61915035t
x1 = trim(upcase(substr(x,1,1)));
I really appreciate what you are doing in this site!
You want to remove leading/trailing blanks from a character string that is the uppercase first letter of the string x. So this should do it.
library(stringr)
x1 = str_trim(str_to_upper(str_sub(x,1,1)))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I would like to get this loop to work. I am trying to save different dataframes with different names at once. I don't know how to get the path part of the code to vary with i:
for (i in specific) {
write.dta(get(paste0("degreeS", i)), "D:/Educacion/PeerEffects/",paste0( "degreeS", i,".dta"))
}
I needed to use the command file.path(). This solved the problem
for (i in specific) {
write.dta(get(paste0("degreeS", i)), file.path("D://Educacion//PeerEffects//", paste0("degreeS", i,".dta")))
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can I achieve somethign like this in R:
like this?
vec <- runif(5)
plot(0,0,type="n",xlim=c(0,1.5),ylim=c(0,7),bty="n",axes="off")
at<-barplot(vec,horiz=TRUE,add=TRUE)
text(vec,at,signif(vec,1),pos=4)
text(rep(1,5),at,c("mn","lu","co","-","my"))