I am relitively new to R and R-Markdown. I am receiving an error message of
! Extra alignment tab has been changed to \cr.
\endtemplate
In Table 4. I do not know what the error is telling me, and I don't know how to fix it. The code in Table 4 is the same format as the other tables. I have spent three days on this, I understand that this my be a simple fix, but I am at a loss.
I have added and subtracted l's and c's from the alignment clause, I have constructed a randomly generated data set, and Table 4 will run as it should. Leading me to believe that there is a problem with that specific column of data.
licen_area<-USC_cola%>%
group_by(Licen_area, .drop=F)%>%
summarise(count=n())%>%
ungroup()%>%
mutate(perc = round((count/sum(count)*100),2))
kable(licen_area,"latex",booktabs=T,align="lcc",
col.names=linebreak(c("Licensure\nArea","Count", "\\%"),align="c"),row.names=F, escape=F)
code
data
Any solutions or workarounds will be most helpful!
There was a special character in the data. Once that was removed it worked fine!
Related
I have a given df which has some column names that include a "/" (e.g. "Province/State" and "Country/Region").
I want to first group the df by "Country/Region" and then summarize it like this:
confirmed_by_country <- confirmed %>%
group_by("Country/Region") %>%
summarize_at(vars(-Lat, -Long, -"Province/State"), sum)
When I try to run this code it tells me that the column "Province/State" does not exist. I was warned about using this problem but still can't figure out what I am doing wrong.
I am also confused why I am only getting this error for "Province/State" and not "Country/Region" in the group_by() function.
does anyone have an idea what the problem might be? Thanks!
Somehow it made a difference whether I imported the data with read.csv() or read_csv().
It didn't work with read.csv() even if I used backticks but it did when I used read_csv() and backticks. (The column names were also different depending on which one I used.)
If anyone knows why that is, I'm interested!
Using dplyr in R (microsoft R Open 3.5.3 to be precise). I'm having a slight problem with dplyr whereby I'm sometimes seeing lots of additional information in the data frame I create. For example, for these lines of code:
claims_frame_2 <- left_join(claims_frame,
select(new_policy_frame, c(Lookup_Key_4, Exposure_Year, RowName)),
by = c("Accident_Year" = "Exposure_Year", "Lookup_Key_4" = "Lookup_Key_4")
)
claims_frame_3 <- claims_frame_2 %>% group_by(Claim.Number) %>% filter(RowName == max(RowName))
No problem with the left_join command, but when I do the second command (group by/filter), the data structure of the claims_frame_3 object is different to that of the claims_frame_2 object. Seems to suddenly have lots of attributes (something I know little about) attached to the RowName field. See the attached photo.
Does anyone know why this happens and how I can stop it?
I had hoped to put together a small chunk of reproducible code that demonstrated this happening, but so far I haven't been successful. I will continue. In the mean time, I'm hoping someone might see this code (from a real project) and immediately know why this is happening!
Grateful for any advice.
Thanks
Alan
This is my first post so I will try to be specific.
I have imported few .csv files and I am trying to combine them together.
When I am inspecting each individual data frame, as I import them, I can open them in RStudio View window and data looks correct.
However once I combine the data frames together using Master<-do.call("rbind", list(DF1,DF2,DF3,DF4)) and try try to view the Master table i get following massage:
Error in if (nchar(col_min_c) >= 16 || grepl("e", col_min_c, fixed =
TRUE) || : missing value where TRUE/FALSE needed
However, when I view all the original data frames I am able to see them with no problem.
If I use utils::View(Master) I am able to see the data frame.
So I am not sure where this issue comes from.
These are the package I am running:
require(data.table)
require(dplyr)
require(sqldf)
require(ggplot2)
require(stringr)
require(reshape2)
require(bit64)
Thanks for any help you can provide
I was able to get around this issue by transforming my table via:
Master<-sqldf("SELECT * FROM 'Master'")
So I hope this helps others in the case they come across a similar issue in the future.
I was able to view the file if I removed NA values from a long numeric column (19 char) on the far left hand side of the table (column 1)
I'm not too advanced with R so any help would be appreciated. I am trying to add values to columns in my dataset and my dataset is called 'katie'.
For example, in the column 'word' I'd like to select instances where 'SUBJECTED' is written and then post 'middle' in the column 'pre.environment', on the same line as 'SUBJECTED' is written. Is there something that I am doing wrong? With this code, the initial line definitely works (as I can see how many "SUBJECTED" items are recognized in the column 'word') but nothing happens when I enter the second line of code.
>x=grep("SUBJECTED", katie$word)
>katie[x,]$pre.environment= c('middle')
I hope this example is sufficient. Thanks in advance for your help.
Try the following code, if I understand your question correctly,
katie$pre.environment <- ifelse(grepl("SUBJECTED", katie$word),
yes = "middle",
no = katie$pre.environment)
Hi all and thanks in advance for all your help.
In R, I'm sending a command to an external Windows program using system(command), which in turn outputs lines (with multiple values per line) that I see directly on the R console. They look something like this:
a,b,c,d,e,f,g,h
1,2,3,4,5,6,7,8
3,4,5,7,1,3,4,9
7,5,3,1,8,1,5,7
What I would like to do is create an array that has the top row as column names and each subsequent row from the input should be the values that go into these columns. Any and all help in making this work would be very appreciated.
This is my first foray into this territory so I'm quite stuck as to how to do it. I've meddled with scan(), pipe() and readLines() but haven't been able to succeed. I have no particular attachment to system(command), any function that will run the executable that will give me the output I need is fine by me if it helps achieve what I want.
The comment made by user1935457 did the trick.
read.table(text = system(command, intern=TRUE), sep = ",", header=TRUE)