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 7 years ago.
Improve this question
I wanted to delete all the columns with "No", such as DIGSANo, SETFANo, ... How do I do it? Thank you!
The data is here
enter link description here
One way could be with dplyr and the functions that work inside select:
iris %>% select(-ends_with("Width"))
In you case you should do something like:
yourData %>% select(-ends_with("No"))
Related
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 3 years ago.
Improve this question
I have some values stored in a dataframe and I would like to take them and use them as variable names. How do I do that without writing/Hardcode the variable name?
You can use the assign() function. Here is an example:
data <- data.frame("Name"=c("John", "Evie", "Graham", "Mary"),
"Age"=c(13,43,26,17), stringsAsFactors=FALSE)
for(row in 1:nrow(data)){
assign(x=data[row, "Name"], value=data[row, "Age"])
}
print(Evie)
$Evie
[1] 43
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 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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 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
I have a dataframe with some records. Then I inserted some rows, using rbind command. Now I want to group the entire dataframe using the three columns, but couldn't get it right.
library(dplyr)
df2 = df %>%
select(key,team, h_date) %>%
group_by(key,team, h_date)
What's the correct way to do this?
I think this might be what you want to do:
df2 = df %>%
select(key,team, h_date) %>%
arrange(key, team, h_date)
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 8 years ago.
Improve this question
I have a data frame that has some empty entries. I set the
options(stringsAsFactors = FALSE)
so that I can change the empty cells. I then wrote the following code:
apply(my_data[,6:65],2, function(x) x[which(x=='')]<-0)
, hoping that it replaces all the empty cells with zeros. But it isn't working!
Note that my_data has 65 columns and columns 1:5 contain string.
Thanks in advance
No need to use apply, just use [<- with logical indexing
my_data[my_data==""] <- 0