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 6 years ago.
Improve this question
I have question about unsplit in R. Really appreciate if you could help.
I splitted a dataframe into smaller dataframes, by two factors.
mydf.list=split(df.original,list(factor1,factor2))
How do I use unsplit to get my dataframe back? I tried following, but didn't work.
df.updated=unsplit(mydf.list,list(factor1,factor2))
Thanks a lot.
I think this is what you are looking for. This example is based on the mtcars dataset, and #thelatemail's comment
data(mtcars) #load dataset
mydf.list<-split(mtcars,list("cyl","vs")) #split the dataset
unsplit(split(mydf.list, list("cyl", "vs") ), list("cyl", "vs")) #rejoin the dataset
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 2 years ago.
Improve this question
It is about the dataset MplsStops from R.
I have selected two column of the dataset I need: race and citationIssued.
After that, I omitted all NAs.
Then I want to filter all citationIssued values by the values Black and White from the column race.
How can I get done that?
Thanks for you help
Welcome to Stack Overflow!
The dplyr package is your friend if you are trying to learn data processing with R.
How about this:
library(carData) # get the sample data
library(dplyr) # load dplyr for data processing functions
MplsStops %>% # start with the data and pipe it to the next line
select(race, citationIssued) %>% # keep two variables and pipe to next line
filter(race %in% c("Black", "White") & !is.na(citationIssued))
If that answers it click the green checkmark and if not add a comment for more help.
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 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 am trying to convert factors from a data-frame to numeric using the commands
data[] <- lapply (data, function(x) as.numeric(as.character(x))
But it keeps asking me for more coding. What am I doing wrong?
The data-frame is named data and it consists of 50 rows and 2 columns. Will this command change every variable in numeric right? Or shall I do something else?
screenshot after using 'dput' at http://imgur.com/Sde9QSk.png
Shouldn't you add ) at the end of your code?
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"))
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