Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm a beginner using R to analyze a bunch of data. My program currently opens a list of csv's from a folder and binds them together into one data frame using rbind. Here's what it looks like:
LDT.list <- list.files(path="./Desktop/Data_analysis/LDT/", pattern=".csv", full.names = TRUE)
LDTfiles <- lapply(LDT.list, read.csv)
LDT_table <- do.call("rbind.data.frame" , LDTfiles)
The problem is that after using rbind, one of the columns in my dataframe is no longer numeric and I can't calculate its mean. I imported a single csv and the column I've described is considered numeric.The problem seems to occur after using rbind. I've already tried to convert the column to numeric but got a warning about missing data. So my question is how I could use rbind while keeping the classes as numerics. Thanks
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to join two data frames using a left_join function. Here is my code:
combined <- left_join(APRN_mailing, DOPL_List, by = "ID")
I keep receiving the error:
"Error: Join columns must be present in data."
When I run colnames() on both data frames I get:
colnames(DOPL_List)
[1]"ID.LAST_NAME.FIRST_NAME.gender.ADDR_LINE_1.ADDR_LINE_2.CITY.STATE.zipcode.EMAIL.LicenseID.ProfessionGroup.Birth_Year"
colnames(APRN_mailing)
[1]"ID.LAST_NAME.FIRST_NAME.gender.ADDR_LINE_1.ADDR_LINE_2.CITY.STATE.zipcode.EMAIL.ProfessionGroup.Birth_Year"
It looks to me like I have a column named "ID" in both data frames. I have tried rewriting the code:
combined <- left_join(APRN_mailing, DOPL_List, by = c("ID" = "ID")
but I get the same result.
Any ideas what the problem might be?
It seems to me that you misread the data, your columns are not separated. If you look at the results of colnames () it only returns the name of a variable, which is very long.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Write an R function which accepts a list of integers and returns only the odd
values in the original list. R has a number of built-in datasets; one of them is
called Nile and a data frame containing these data is added to your working
environment with the command data(‘Nile’). How many of the entries in this
dataset are odd?
What I've written is
return.odd<-function(y)return(y[y%%2=1])
length(return.odd(Nile))
But it returns
Error: unexpected '=' in "return.odd<-function(y)return(y[y%%2="
and
Error in return.odd(Nile) : could not find function "return.odd"
Could you please tell where my mistakes are?
return_odd <- function(x) {
x[x %% 2 == 1]
}
length(return_odd(Nile))
[1] 27
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am new in R and I would like to ask what is wrong in the following simple command. When i try:
for (k in 1:1){
logdata= logDataset[1:74+k,k]}
logdata collects the values from rows 2:75 of column 1 of the logDataset data frame. But when I use:
logdata=logDataset[1:75,1]
logdata collects correctly the first 75 values of the first column. Why the first command does not work as the second one? How can I use the "for" command for collecting the first 75 values of the first column? Many thanks.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Im using Rstudio and I can't seem to solve this problem:
I have a df which I want to subset by taking only some columns and so I do the following:
dfo <- read.csv("cwurData.csv")
df<- subset(dfo, c=("world_rank", "country", "quality_of_education",
"alumni_employment", "publications", "patents", "year"))
To which I get the following error: (and I can't see why!)
Error: unexpected ',' in "df<- subset(dfo, c=("world_rank","
Thanks for your help:)
I am assuming that all the quoted names are names of columns you want to select, if so the problem is that you are not using the select argument in the subset function (see ?subset for details). An example of how to use this function on the diamonds data set from ggplot2 can be seen below:
install.packages('ggplot2')
library(ggplot2)
diamonds
subset_d= subset(diamonds,select=c('cut','color'))
Also just some other things to note, you look like your attempting to assign a vector of character values to c by doing c=('x','y','z',...), just a reminder that you need to instead do c=c('x','y','z',...), the c before the parentheses being a combine function call. Good practice would also be to assign vectors to variable names other than 'c', as this causes confusion with the function name. Let me know of any other questions.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Suppose I have a very simple data frame:
symbol <- c("A", "A^","B","C","C^")
df = data.frame(symbol)
Now imagine this is a very large dataframe so that I cannot easily list the rows in which the character "^" appears.
How can I subset the rows with (or without) that character?
Notice that things like:
df[grep("^", df$symbol)
or regular subsetting will not work since the carat "^" is usually used to represent the beggining of a string.
Many thanks
Add fixed to the grep function, as follows:
df[grep("^", df$symbol, fixed=T),]