Computed variable gives unexpected counts [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 days ago.
Improve this question
I have a problem with the coding of some variables. I am working on data for Lebanon on R on two different datasets, the World Value Survey and the Arab Barometer. Regardless of the dataset I am using, when I try to code a variable referring only to one country (in this case Lebanon), the values of the variable at the end of the coding are entirely wrong.
I have tried the same coding with other variables and with another dataset, but the problem remains, and the values are still much larger than they should be.
As can be seen from the values in the 'table' command, the values after encoding are very different.
As a beginner, I'm sure my question will be trivial, but I'm asking for help to unblock the situation.

Related

Specific variables calculation [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 1 year ago.
Improve this question
Hello,I have an issue.I have an excell and I want to calculate and to find Min. =0.000 etc..but I find Min. =1.700 etc. What am I doing wrong here?
I believe the problem is your inclusion of & grade as a term in your filter step.
What's going on is that R wants to interpret each of these terms (exam=="S1", year==2018, grade) as a logical value. When it converts grade to logical, 0 becomes FALSE and all other values become TRUE (try as.logical(-1:1) to see an example), so the zero values in your data get removed.
Just delete & grade from your code.

Why are these states not displaying the data when the data exists with the usmap package? [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 2 years ago.
Improve this question
I'm trying to plot election results on the US map with the usmap package but even though the dataset is complete, I get plot that shows missing values for some states. The states are greyed out and I'm not sure why this is happening..
plot_usmap(data=data_total,values='percent_biden')+
scale_fill_continuous(low='red',high='blue',name='Percent for Biden')+
theme(legend.position='right')+
ggtitle(paste("Total Popular Vote of Final Results"))
You are incorrectly assuming that usmap will infer any format for state names. For instance, both of these produce a working map,
usmap::plot_usmap(data=data.frame(state=c("alabama","new york"),s=c(5,15)), values="s")
usmap::plot_usmap(data=data.frame(state=c("AL","NY"),s=c(5,15)), values="s")
whereas inferring from your pic of data, you are trying
usmap::plot_usmap(data=data.frame(state=c("alabama","new-york"),s=c(5,15)), values="s")
# ^ dash, not space
So I believe you need to clean up your data and fix your state names.

How to create this chart in R? [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 3 years ago.
Improve this question
I have a task a bit complicated for my knowledge in R. I need to reproduce this graphic of the figure in R, I performed several searches and could not find anything. The main thing is to be able to reproduce the graphic (it doesn't have to be identical), subtitles are not so important. Any ideas on how to do it or just using another program? Thanks!!
Check also the facet_share() function of the ggpol package, very handy for population pyramids/comparisons

How to calculate difference between dates in R [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 working on a project right now and encountered this problem.
I have a dataset consisting of two dates columns. One, say it x1, stands for check-in dates, the other, say it x2, stands for check-out dates.
Both of them are in the "year-month-day" format and have the type of string.
What I would like to do is figuring out how long does a person stay using check-in, check-out dates. I've tried multiple functions like as.Date. But all failed and I believe I just can't subtract these two dates directly as the results wouldn't represent the actual stay length.
Does anybody have any idea on how to do this in R?
Thanks!
If I understood your question, you want the difference between checkout and checkin? I would try this:
library(lubridate)
df<-data.frame(x1=c("2017-03-23","2017-03-24"),x2=c("2017-03-24","2017-03-28"))
df[]<-lapply(df,ymd)
df$x2-df$x1

Finding i values where Y = a number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm a student just learning how to use R and thus far I've made a bit of progress. I'm snagging at a question which asks: For what values of i does Y equal 3?
the data set: c(3,5,2,3,5,4,4,2,3,5)
If I understand your question correctly, you want the index, i inside the data set (in this case, a vector) Y such that Y[i]=3?
Then you just need to use the which function. For more information, make sure you try reading the help files, which you can invoke using the command ?which or help(which)
Now, some code:
# Your data
Y <- c(3,5,2,3,5,4,4,2,3,5)
# Find the index where Y is equal to 3
which(Y==3, arr.ind=TRUE)
And welcome to SO. This is a pretty common question for beginners, so next time, make sure you Google or search around for a solution to elementary problems such as these. Have a good day.

Resources