Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have this function to create a dataset which includes all my prediction I have made before:
tst=setNames(
data.frame(
expand.grid(unique(df_sum[,"id"]),unique(df_sum[,"training"]),seq(25,100,25))
)
)
Unfortunately, this message comes:
Error in setNames(data.frame(expand.grid(unique(df_sum[, "id"]),
unique(df_sum[, : argument "nm" is missing, with no default
It is a big dataset, so, it is hard to share. I hope you have enough details to help me.
Thanks
If you run help("setNames") you will find under the heading "Usage" that setNames takes two arguments, called object and nm. The latter is missing in your call.
If your dataset is to large to share, please use a tiny part of it or some simulated data to publish small reproducible examples of what you try to do. We all have the iris dataset and a reproducible example for your problem might be as simple as
> setNames(iris)
Error in setNames(iris) : argument "nm" is missing, with no default
The answer is then
head( setNames(iris, nm = c("name1", "name2", "name3")) )
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to use the match function in function with a for loop and it isn't working. Here is an example of the exact error I'm getting.
a <- c(1:10)
b <- c(2:11)
match(a,b)
It doesn't work. Here is the error I'm getting:
Error in match(a, b) : unused argument (b)
Then I tried something simpler:
match(2,a)
And it gives me this:
Error in match(2, a) : unused argument (a)
I really need this function for my code, can anyone tell me what I've done wrong?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Not sure what exactly the error is here I'd appreciate some insight. My code is as follows, and I checked the structure of the df rbbq, there is definitely a column called 'Shrimp' in it.
bbq1 = read.table('c:/Users/***/Documents/bbq.txt', sep=' ',
header=T)
bbq2 = read.table('c:/Users/***/Documents/bbqshrimp.txt', sep=' ',
header=T)
rbbq = merge(bbq1, bbq2, by='City')
finalbbq = subset(rbbq, rbbq$Shrimp=="Yes", select=c('City', 'State' ))
Error in `[.data.frame`(x, r, vars, drop = drop) :
undefined columns selected
I would use dplyr however that's not how the professor wants us to accomplish this. I am just trying to pull out the city and state of the locations which have, "Yes" for the Shrimp variable. Thanks for any help! This question is specific to the subset function, and not just a matter of calling up the specific lines.
EDIT: Final workaround was to assign my dataframe to another name, and that did the trick.
Remove the rbbq$from rbbq$Shrimp. Also, pretty sure city and state don't need to be quoted.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have searched for answers to my question and can't seem to find any answer. I am trying to sort my data so that I can first sort by year of birth and then by last name. Here is my code:
ResidentsBD_99_2015_clean < ResidentsBD_99_2015_clean[order(ResidentsBD_99_2015_clean[, birthdate_year],
ResidentsBD_99_2015_clean[, "surname"],
decreasing = FALSE), ]
When I run this code, this is the error message that I recieve:
Error in `[.data.frame`(ResidentsBD_99_2015_clean, , birthdate_year) :
undefined columns selected
You might just be stuck with typos in your code. birthdate_year should be quoted. It also looks like you have a typo in the assign-operator (<-).
In a more general sense, I prefer ordering with dplyr.
library(dplyr)
ResidentsBD_99_2015_clean <- arrange(ResidentsBD_99_2015_clean, birthdate_year, surname)
From what I can see from your code, it might just be the missing - in the assignment and some small syntax problem. Try this:
ResidentsBD_99_2015_clean<- ResidentsBD_99_2015_clean[order(ResidentsBD_99_2015_clean$birthdate_year, ResidentsBD_99_2015_clean$surname),]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Im using Rstudio and I can't seem to solve this problem:
I have a df which I want to subset by taking only some columns and so I do the following:
dfo <- read.csv("cwurData.csv")
df<- subset(dfo, c=("world_rank", "country", "quality_of_education",
"alumni_employment", "publications", "patents", "year"))
To which I get the following error: (and I can't see why!)
Error: unexpected ',' in "df<- subset(dfo, c=("world_rank","
Thanks for your help:)
I am assuming that all the quoted names are names of columns you want to select, if so the problem is that you are not using the select argument in the subset function (see ?subset for details). An example of how to use this function on the diamonds data set from ggplot2 can be seen below:
install.packages('ggplot2')
library(ggplot2)
diamonds
subset_d= subset(diamonds,select=c('cut','color'))
Also just some other things to note, you look like your attempting to assign a vector of character values to c by doing c=('x','y','z',...), just a reminder that you need to instead do c=c('x','y','z',...), the c before the parentheses being a combine function call. Good practice would also be to assign vectors to variable names other than 'c', as this causes confusion with the function name. Let me know of any other questions.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I made an upgrade in R, and since then, I have a lot of errors in programs which were working well before.
The one I cannot go around is :
Error: could not find function "setnames"
I am loading the packages (
library(plyr)
library(dtplyr)
library(tidyr)
library(lsr)
library(ggplot2)
library(stats)
and i am using R :
platform x86_64-w64
major 3
minor 3.2
Does anybody knows how to go around please ?
It's probably a typo, if you're referring to setNames in stats.
Remember to capitalize the 'n'.
See https://stat.ethz.ch/R-manual/R-devel/library/stats/html/setNames.html
(The other possibility is that you may not have loaded the data.table package. See, for example, Using data.table::setnames() when some column names might not be present)