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")))
}
Related
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 days ago.
Improve this question
I want to run a binary logistic regression in R but I see this error:
Error in if (!length(fname) || !any(fname == zname)) { :
missing value where TRUE/FALSE needed
It happens because I use variables with $. For example data$HEIGHT.
I use read.table() for importing .txt file.
How can I use HEIGHT instead of data$HEIGHT?
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 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")
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 9 years ago.
Improve this question
Given the following setup:
area.factor <- cut(state.x77[,"Area"],
breaks=quantile(state.x77[,"Area"],c(0,.25,.75,1)),
labels=c("small","medium","large"),
include.lowest=TRUE)
state <- data.frame(pop=state.x77[,"Population"],
inc=state.x77[,"Income"],
area=area.factor,
region=state.region)
pop.area.region <- with(state,ftable(pop,area,region))
The following two lines of code are show the same result:
head(ftable(prop.table(pop.area.region,margin=2)))
head(prop.table(pop.area.region,margin=2))
I don't understand what effect adding ftable has, if any, in:
head(ftable(prop.table(pop.area.region,margin=2)))
Adding ftable witll try to coerce the pop.area.region to a ftable class. Here
No need to add ftable since pop.area.region is already an ftable.
identical(ftable(prop.table(pop.area.region,margin=2)),
prop.table(pop.area.region,margin=2))
TRUE