Select two certain values of a column in R RStudio [closed] - r

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.

Related

Error in gathering many columns together using R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am beginner in R. I am looking to gathering some columns for plotting. I got this error "Error: Must supply a symbol or a string as argument". I would be happy if you help me in how to fix this error.
library(readxl)
df =read_excel("a1-cereals.xls")
# Select columns
df%>% select (c(-1,-2,-11,-14,15))->df1
# Filtering rows
df_Type_C <- filter (df1, Type == "C")
head (df_Type_C)
df_Type_H <- filter (df1, Type == "H")
head (df_Type_C)
#Gathering columns to make a long table
df_long <- gather (df1,Mes_Type,2:11)
This is a sample of the dataset I am working on:
This happens because gather requires a name and value argument (supplied as strings, hence the error message. I imagine that supplying this would solve your problem. However, I strong encourage you to change from gather to the pivot arguments as gather has been retired. I think your code would work fine with pivot. Please see links below and good luck!
Link1
Link2

Dataframe convert factors to numerical error [closed]

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?

Dplyr transmute reports error: unexpected ',' - but commas are part of the command? [closed]

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
This dplyr-command usually works just perfect for me, when I want to recode variables. But for some reason it all of the sudden hates the commas, but won't run without them... I have (re)installed both haven and dplyr several times. Any ideas? The first words are Danish names of variables.
OLS <- cses %>%
transmute(efficacy=iA3029_m,
uddannelse=iA2003_m,
køn=iA2002_m-1,
alder=iA2001_m,
husindkomst=iA2012_m,
arbejdsløs=ifelse(iA2007_m==5,1,0),
sektor=convert_to_NA(as.factor(iA2009_m1),3),
højre-venstre=convert_to_NA(as.numeric(iA3031_m),95),
civilstand=ifelse(iA2004_m1==1,1,0),
religiøs=iA2016_m,
land-by=iA2022_m,
polviden,
aar,
land) %>%
You can't have an unqouted minus sign as a named parameter value to a function. This is not allowed
mtcars %>% transmute(disp-cyl=disp-cyl)
But this is allowed (though not recommended)
mtcars %>% transmute("disp-cyl"=disp-cyl)
it's better to use a valid variables names as columns. Perhaps use an underscore
mtcars %>% transmute(disp_cyl=disp-cyl)

r unsplit to get original dataframe back [closed]

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

How to plot a radar plot in R like the one in excel for the same data frame [closed]

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 this data frame made in R :
Technical Junior Entry-Level Product Owner Technical Leader Senior
Professional 2,236 3,581 3,781 3,654 4,454
Communication 2,619 3,333 4,285 4,190 4,952
Innovation 3,625 4,208 4,500 4,000 4,791
And I want to plot something like that in R (I have made this in Excel)
Radar plot made in excel
Please help me to make this graph through R cause I failed making it with ggplot, ggtern, plotrix and other libraries I cannot manage properly.
I did it very easily using fmsb::radarchart(). Note I had to remove the commas first from your data, which I then read in as df. I also had to add rows for the min and max to reproduce your Excel plot.
library(fmsb)
df1 <- data.frame(t(df))
dfminmax <- rbind(rep(max(df1), 3) , rep(min(df1), 3) , df1)
radarchart(dfminmax)
You're going to want to tweak the settings to make it look better. Use ?radarchart to find out all the options.

Resources