0

When I run my code, I always have the same error, I don´t know what I´m doing wrong

# I upload these packages because I need to work with my data base, join some databases 
library(tidyverse)
library(fitdistrplus)
library(MASS)
library(survival)
#these are my data frames 
df41 = read.table("2014_1.csv",sep=";",header=T)
df42 = read.table("2014_2.csv",sep=";",header=T)
df43 = read.table("2014_3.csv",sep=";",header=T)
df44 = read.table("2014_4.csv",sep=";",header=T)
df51 = read.table("2015_1.csv",sep=";",header=T)
df52 = read.table("2015_2.csv",sep=";",header=T)
df53 = read.table("2015_3.csv",sep=";",header=T)
df54 = read.table("2015_4.csv",sep=";",header=T)
df61 = read.table("2016_1.csv",sep=";",header=T)
df62 = read.table("2016_2.csv",sep=";",header=T)
df63 = read.table("2016_3.csv",sep=";",header=T)
df64 = read.table("2016_4.csv",sep=";",header=T)
df71 = read.table("2017_1.csv",sep=";",header=T)
df72 = read.table("2017_2.csv",sep=";",header=T)
df73 = read.table("2017_3.csv",sep=";",header=T)
df74 = read.table("2017_4.csv",sep=";",header=T)
df81 = read.table("2018_1.csv",sep=";",header=T)
df82 = read.table("2018_2.csv",sep=";",header=T)
df83 = read.table("2018_3.csv",sep=";",header=T)
df84 = read.table("2018_4.csv",sep=";",header=T)
df91 = read.table("2019_1.csv",sep=";",header=T)
#some tests that im doing with my data frames
names(df41)
names(df42)
names(df41) == names(df42)
str(df41)
summary(df41)
names(df41)
#Here, I choose the columns "POTENCIA_BRUTA_MWH" and "CONCENTRACION_PORCENTAJE_CO2" and then I filter them with the values distinct of 0 or NA
df41_n = df41 %>% select(c("POTENCIA_BRUTA_MWH","CONCENTRACION_PORCENTAJE_CO2")) %>%
    filter(POTENCIA_BRUTA_MWH != 0 | POTENCIA_BRUTA_MWH != is.na(df41),CONCENTRACION_PORCENTAJE_CO2 != 0 | CONCENTRACION_PORCENTAJE_CO2 != is.na(df41))
summary(df41_n$POTENCIA_BRUTA_MWH)
summary(df41_n$CONCENTRACION_PORCENTAJE_CO2)

When I run my code, in the line of df41_n, they always show me that error:

df41_n = df41 %>% select(c("POTENCIA_BRUTA_MWH","CONCENTRACION_PORCENTAJE_CO2")) %>%
    +     filter(POTENCIA_BRUTA_MWH != 0 | POTENCIA_BRUTA_MWH != is.na(df41),CONCENTRACION_PORCENTAJE_CO2 != 0 | CONCENTRACION_PORCENTAJE_CO2 != is.na(df41))

Error in select(., c("POTENCIA_BRUTA_MWH", "CONCENTRACION_PORCENTAJE_CO2")) Error in select (c("POTENCIA_BRUTA_MWH", "CONCENTRACION_PORCENTAJE_CO2"))

But the lines:

summary(df41_n$POTENCIA_BRUTA_MWH)
summary(df41_n$CONCENTRACION_PORCENTAJE_CO2)

works very well, so, I don't know what I'm doing wrong

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • 2
    It's hard to know what's going on with code that requires reading in 21 files when we can't see any of them. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making R questions folks can more easily help with. My guess is that you've given a vector to `select`, when, if you look at the docs for `dplyr::select`, it expects a set of bare column names, not a vector – camille Oct 27 '19 at 22:40
  • all the files are only CSV, that contains 42 columns and approximate 200000 rows; I tried with : df41_n = df41 %>% select ("POTENCIA_BRUTA_MWH","CONCENTRACION_PORCENTAJE_CO2") %>% filter(POTENCIA_BRUTA_MWH != 0 | POTENCIA_BRUTA_MWH != is.na(df41),CONCENTRACION_PORCENTAJE_CO2 != 0 | CONCENTRACION_PORCENTAJE_CO2 != is.na(df41)), but it doesnt works – Vicho Dániel Oct 27 '19 at 22:48
  • So what do you want to achieve? I advise to just first do the simplest thing possible on the dataframe and do more complicated stuff as you go. I mean just get one column first from the table and continue from there. – Ansjovis86 Oct 27 '19 at 23:14
  • I tried to remove the double quotes and also tried with only one column, but they still doesn't work – Vicho Dániel Oct 27 '19 at 23:27
  • by the way Thanks – Vicho Dániel Oct 27 '19 at 23:28
  • The error says that the problem is in using syntax like `c("column1", "column2")` inside your `select` call. Whatever isn't working is something we can't check, sine we don't have access to any of your data. If the question is only about a single data frame, then you can [edit] to make it only that, not about reading 20 other files – camille Oct 28 '19 at 00:17
  • Hi, welcome to SO, you should check out: https://stackoverflow.com/help/minimal-reproducible-example - for advice on writing a question. dput is a good function to know – MatthewR Oct 28 '19 at 01:19

0 Answers0