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.
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 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")) )
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
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.
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.
Improve this question
Fundamental stuff but i couldn't seem to get around this. I performed the following process:
d1<-read.csv('hourly.csv',sep=",",header=F)
names(d1)<-c("date","rain","q","qa","qb")
d2<-read.csv('event.csv',sep=",",header=F)
names(d2)<-c("enum","st","et","rain2","qtot")
for(k in 1:206){
st<-d2[k,2]
et<-d2[k,3]
Datetime<-d1[st,]
print(Datetime)
write.csv(Datetime, file="DatesA3.csv")
}
In the end, i exported the results to a csv file. There are 206 rows altogether and they display fine in R. But when exporting, only the last row is exported in the csv file. I tried multiple things such at write.table, append, etc. but nothing seems to work.
How do i export every row into one file?
Please advise and thank you!
Datetime[k, ] <- d1[st, ] # instead, otherwise you overwrite
# and write the result outside the loop
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 needs debugging details. It is not currently accepting answers.
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.
Closed 5 years ago.
Improve this question
I need to replace number values with something that makes more sense to the reader.
Value “-0.95197” represents “18-24” age group in the given table.
What would be the best way to go about this for all columns?
Your question is a little unclear. Are you trying to rename the header of each column in a data.frame? If so, try this, where df is the name of your data.frame. You need one piece of text for each column.
names(df) <- c("your", "header", "names", "go", "here")
If this is not what you want, then you need to provide more info.