Undefined Columns Selected (when using order function) [closed] - r

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),]

Related

The length() function is not returning the right number [closed]

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 7 months ago.
Improve this question
I working with a csv that has 234 rows. I thought the length() function was supposed to return the number of rows in my csv, but it returns a much larger number. It gives me 1046860. Does the length function not do what I think it does? What is going on?
I just wanted to double check the length and haven't run any other code yet other than setting up my working directory and attaching a file (Cat6 <- read.csv("Category6.csv")).

subset R undefined columns [closed]

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.

How to choose the first "n" elements in R [closed]

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
(USING R)
So I imported a data set by using
xcars <- read.csv(file.choose())
and then I chose my data set which was originally an excel file.
So, I have a column named dist (short for displacement) and I want to choose the first 25 entries underneath that column and then plot it on a histogram, so I attempted the following.
carsUpTo25 <- xcars(1:25,)
hist(carsUpTo25$dist)
Of course this didn't work. However, any help on how I would do this would be helpful.
Try this-
hist(xcars[,dist[1:10]])

Function error in R "setnames" [closed]

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)

has the %between% command in R been removed? [closed]

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 7 years ago.
Improve this question
I am returning to some old code where I had used the following syntax:
y[df$myvar %between% c(1,100)]
but get the error
could not find function "%between%"
This code used to work, and I have updated R in the mean time. any thoughts?
As Pascal pointed out, you should load the package data.table first:
library(data.table)
Then you'll be able to use it.

Resources