Cannot import a simple vector in R : why? [duplicate] - r

This question already has answers here:
R eval parse character limit
(1 answer)
Command Lines error in Rstudio console
(1 answer)
Closed 1 year ago.
I would like to import in R this vector that contains the names of several variables :
names14 <- c("INAMI","HcwProfession","code_qualif","espaces","start_convention","end_convention","date_adh_convention","date_refus_convention","n_limitations","jour_a1","h_s_a1","m_s_a1","h_e_a1","m_e_a1","jour_b1","h_s_b1","m_s_b1","h_e_b1","h_e_b1","na1","type1","INAMI1","lieu1","postal1","ins1","local1","province1","com1","start1","end1","jour_a2","h_s_a2","m_s_a2","h_e_a2","m_e_a2","jour_b2","h_s_b2","m_s_b2","h_e_b1","h_e_b1","na2","type2","INAMI2","lieu2","postal2","ins2","local2","province2","com2","start2","end2","jour_a3","h_s_a3","m_s_a3","h_e_a3","m_e_a3","jour_b3","h_s_b3","m_s_b3","h_e_b1","h_e_b1","na3","type3","INAMI3","lieu3","postal3","ins3","local3","province3","com3","start3","end3","jour_a4","h_s_a4","m_s_a4","h_e_a4","m_e_a4","jour_b4","h_s_b4","m_s_b4","h_e_b1","h_e_b1","na4","type4","INAMI4","lieu4","postal4","ins4","local4","province4","com4","start4","end4","jour_a5","h_s_a5","m_s_a5","h_e_a5","m_e_a5","jour_b5","h_s_b5","m_s_b5","h_e_b1","h_e_b1","na5","type5","INAMI5","lieu5","postal5","ins5","local5","province5","com5","start5","end5","jour_a6","h_s_a6","m_s_a6","h_e_a6","m_e_a6","jour_b6","h_s_b6","m_s_b6","h_e_b1","h_e_b1","na6","type6","INAMI6","lieu6","postal6","ins6","local6","province6","com6","start6","end6","jour_a7","h_s_a7","m_s_a7","h_e_a7","m_e_a7","jour_b7","h_s_b7","m_s_b7","h_e_b1","h_e_b1","na7","type7","INAMI7","lieu7","postal7","ins7","local7","province7","com7","start7","end7","jour_a8","h_s_a8","m_s_a8","h_e_a8","m_e_a8","jour_b8","h_s_b8","m_s_b8","h_e_b1","h_e_b1","na8","type8","INAMI8","lieu8","postal8","ins8","local8","province8","com8","start8","end8","jour_a9","h_s_a9","m_s_a9","h_e_a9","m_e_a9","jour_b9","h_s_b9","m_s_b9","h_e_b1","h_e_b1","na9","type9","INAMI9","lieu9","postal9","ins9","local9","province9","com9","start9","end9","jour_a10","h_s_a10","m_s_a10","h_e_a10","m_e_a10","jour_b10","h_s_b10","m_s_b10","h_e_b1","h_e_b1","na10","type10","INAMI10","lieu10","postal10","ins10","local10","province10","com10","start10","end10","jour_a11","h_s_a11","m_s_a11","h_e_a11","m_e_a11","jour_b11","h_s_b11","m_s_b11","h_e_b1","h_e_b1","na11","type11","INAMI11","lieu11","postal11","ins11","local11","province11","com11","start11","end11","jour_a12","h_s_a12","m_s_a12","h_e_a12","m_e_a12","jour_b12","h_s_b12","m_s_b12","h_e_b1","h_e_b1","na12","type12","INAMI12","lieu12","postal12","ins12","local12","province12","com12","start12","end12","jour_a13","h_s_a13","m_s_a13","h_e_a13","m_e_a13","jour_b13","h_s_b13","m_s_b13","h_e_b1","h_e_b1","na13","type13","INAMI13","lieu13","postal13","ins13","local13","province13","com13","start13","end13","jour_a14","h_s_a14","m_s_a14","h_e_a14","m_e_a14","jour_b14","h_s_b14","m_s_b14","h_e_b1","h_e_b1","na14","type14","INAMI14","lieu14","postal14","ins14","local14","province14","com14","start14","end14","jour_a15","h_s_a15","m_s_a15","h_e_a15","m_e_a15","jour_b15","h_s_b15","m_s_b15","h_e_b1","h_e_b1","na15","type15","INAMI15","lieu15","postal15","ins15","local15","province15","com15","start15","end15","jour_a16","h_s_a16","m_s_a16","h_e_a16","m_e_a16","jour_b16","h_s_b16","m_s_b16","h_e_b1","h_e_b1","na16","type16","INAMI16","lieu16","postal16","ins16","local16","province16","com16","start16","end16","jour_a17","h_s_a17","m_s_a17","h_e_a17","m_e_a17","jour_b17","h_s_b17","m_s_b17","h_e_b1","h_e_b1","na17","type17","INAMI17","lieu17","postal17","ins17","local17","province17","com17","start17","end17","jour_a18","h_s_a18","m_s_a18","h_e_a18","m_e_a18","jour_b18","h_s_b18","m_s_b18","h_e_b1","h_e_b1","na18","type18","INAMI18","lieu18","postal18","ins18","local18","province18","com18","start18","end18","jour_a19","h_s_a19","m_s_a19","h_e_a19","m_e_a19","jour_b19","h_s_b19","m_s_b19","h_e_b1","h_e_b1","na19","type19","INAMI19","lieu19","postal19","ins19","local19","province19","com19","start19","end19","jour_a20","h_s_a20","m_s_a20","h_e_a20","m_e_a20","jour_b20","h_s_b20","m_s_b20","h_e_b1","h_e_b1","na20","type20","INAMI20","lieu20","postal20","ins20","local20","province20","com20","start20","end20","jour_a21","h_s_a21","m_s_a21","h_e_a21","m_e_a21","jour_b21","h_s_b21","m_s_b21","h_e_b1","h_e_b1","na21","type21","INAMI21","lieu21","postal21","ins21","local21","province21","com21","start21","end21","jour_a22","h_s_a22","m_s_a22","h_e_a22","m_e_a22","jour_b22","h_s_b22","m_s_b22","h_e_b1","h_e_b1","na22","type22","INAMI22","lieu22","postal22","ins22","local22","province22","com22","start22","end22","jour_a23","h_s_a23","m_s_a23","h_e_a23","m_e_a23","jour_b23","h_s_b23","m_s_b23","h_e_b1","h_e_b1","na23","type23","INAMI23","lieu23","postal23","ins23","local23","province23","com23","start23","end23","jour_a24","h_s_a24","m_s_a24","h_e_a24","m_e_a24","jour_b24","h_s_b24","m_s_b24","h_e_b1","h_e_b1","na24","type24","INAMI24","lieu24","postal24","ins24","local24","province24","com24","start24","end24")
But R tells me something is missing (it shows "+", telling me to add something), but I don't understand what ? It works if I shorten the vector, maybe it's too long ?

Related

Why it is unable to write \delta inside a print command in "R"? [duplicate]

This question already has answers here:
Error: '\R' is an unrecognized escape in character string starting "C:\R"
(5 answers)
R - Unable to replace unrecognized escape symbol "\&" in character string
(1 answer)
Closed 24 days ago.
I want to insert a delta inside a print command in R. Expect \delta all the greek letters are coming without any error. However, the following error is prompted when trying to print \delta using the sprintf command. Can you help?
I tried searching for an answer and found one. But the solution was to use a forward slash which obviously won't work in my case.

What's the difference between using 'mean(Complete_measurements$`High Freq (Hz)`)' and 'mean(Complete_measurements[4])'? [duplicate]

This question already has answers here:
The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframe
(11 answers)
Dynamically select data frame columns using $ and a character value
(10 answers)
Closed 4 months ago.
This post was edited and submitted for review 4 months ago and failed to reopen the post:
Original close reason(s) were not resolved
So I'm working through a multivariate analysis for a project and trying to familiarize myself with R as I do so, and I keep getting the error
Warning message:
In mean.default(Complete_measurements[4]) :
argument is not numeric or logical: returning NA
I'm not using 'mean.default' anywhere, but I have tracked the specific location to just my mean(complete_measurements[4])
I've noticed that when I instead use mean(Complete_measurements$High Freq (Hz)) it seems to work fine, but since I'm intending to use an array of data (ie columns 4-11), I was wondering if there was an easy solution to do so?
Thanks in advance!
So I've tried and gotten:
> mean(Complete_measurements$`High Freq (Hz)`)
[1] 6689.791
> mean(Complete_measurements[4])
[1] NA
Warning message:
In mean.default(Complete_measurements[4]) :
argument is not numeric or logical: returning NA
I expected to get the same result for both? So the 6689.791, but I'm not sure why I get the error instead
Edit: while I get an answer when using '''mean(Complete_measurements[[4]])''', it gives me a different one - any reason why?

In R, how to change working directory more easily? [duplicate]

This question already has answers here:
Escaping backslash (\) in string or paths in R
(4 answers)
Closed 1 year ago.
In how to change working directory more easily?
Currently, if we use 'setwd',we have to add many '\', sometimes it's boring
Is there any easier way for this ? (Just like Python can add 'r' )
setwd('C:\Users\Administrator\Desktop\myfolder') # can't work
setwd('C:\\Users\\Administrator\\Desktop\\myfolder') # can work,but havt to add many '\'
You could use r (for raw string) and add parenthesis:
> r"(C:\Users\Administrator\Desktop\myfolder)"
[1] "C:\\Users\\Administrator\\Desktop\\myfolder"
>
And now:
setwd(r"(C:\Users\Administrator\Desktop\myfolder)")
Or reading from clipboard automatically adds the extra slashes:
setwd(readClipboard())

Why is there a space between strings when using the 'paste' function in R? I have used a separator [duplicate]

This question already has answers here:
What are the differences between "=" and "<-" assignment operators?
(9 answers)
What's the difference between `=` and `<-` in R? [duplicate]
(2 answers)
Closed 2 years ago.
When I input the following paste command:
rdsfile<-paste("Eobs","tmean","_81_10.rds",sep="")
I get: "Eobstmean_81_10.rds"
When I change the equals sign to the arrow usually used in R:
rdsfile<-paste("Eobs","tmean","_81_10.rds",sep<-"")
I get: "Eobs tmean _81_10.rds " (Note the space between "Eobs" and "tmean" and again between "tmean" and "_81_10.rds"
What is causing this to happen?
Parameters in functions should be assigned with an equals sign as in your first example so that you get your desired output.
What you are doing in your second example is to create a global object called sep with value "". You can easily check this by looking into your environment. Or simply type sep into the console.
But this global object sep is not used in the paste function, so the paste function falls back to its default, which is using a space (" ") as the separator.
Long story short: don't use <- for parameter assignments in functions.

How to check if data frame exists in R environment? [duplicate]

This question already has an answer here:
Verify object existence inside a function in R [duplicate]
(1 answer)
Closed 5 years ago.
I am trying to add rows to a data frame if it exists, or assign it to initial data frame in case it doesn't exists. I have tried exists(), missing(), etc, but nothing is working for me.
exists(data) && is.data.frame(get(data))
Error in exists(data) : object 'data' not found
Any help would be highly appreciated.
I am trying to do something like
if(exists(data))
data <- rbind(data,new_data)
else
data <- new_data
If you read the documentation you’ll see that it says that exists requires
a variable name (given as a character string).
In other words, write:
exists('data') && is.data.frame(get('data'))

Resources